go

Google App Engine ModuleHostname: not an App Engine context

与世无争的帅哥 提交于 2021-01-05 09:24:28
问题 I am trying to discover other deployed services on the App Engine. Something like this article suggests. This is how my code looks like: import ( "fmt" "net/http" "google.golang.org/appengine" ) func ServiceHostname(serviceName string, r *http.Request) (string, error) { ctx := appengine.NewContext(r) hostname, err := appengine.ModuleHostname(ctx, serviceName, "", "") if err != nil { return "", fmt.Errorf("unable to find service %s: %v", serviceName, err) } return hostname, nil } I am calling

Google App Engine ModuleHostname: not an App Engine context

核能气质少年 提交于 2021-01-05 09:24:24
问题 I am trying to discover other deployed services on the App Engine. Something like this article suggests. This is how my code looks like: import ( "fmt" "net/http" "google.golang.org/appengine" ) func ServiceHostname(serviceName string, r *http.Request) (string, error) { ctx := appengine.NewContext(r) hostname, err := appengine.ModuleHostname(ctx, serviceName, "", "") if err != nil { return "", fmt.Errorf("unable to find service %s: %v", serviceName, err) } return hostname, nil } I am calling

Golang IPv6 server

放肆的年华 提交于 2021-01-05 08:06:09
问题 How to create ipv6 server. ipv4 server looks like package main import ( "fmt" "net/http" ) func h(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Test") } func main() { http.HandleFunc("/", h) http.ListenAndServe(":80", nil) } but how to listen ipv6 in 80 port 回答1: It already is listening on ipv6 (as well as ipv4). func ListenAndServe(addr string, handler Handler) error { server := &Server{Addr: addr, Handler: handler} return server.ListenAndServe() } // ListenAndServe listens on

如何使用beego快速开发web系统【Golang 入门系列十三】

怎甘沉沦 提交于 2021-01-05 02:55:28
接着之前的内容,前面已经讲过很多Golang的基础语法,mysql的使用,redis的使用,也讲了orm框架,如何创建一个webapi 服务等等,感兴趣的可以看看以前的文章, https://www.cnblogs.com/zhangweizhong/category/1275863.html , 今天要来说一说,如何用beego开发web应用。 介绍 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,同时也是一个关注度和使用量都比价高的开源项目。我认为它是go初学者比较容易上手的一门MVC Web框架。 它是由国内团队开发的开源框架,文档基本都是中文,简单易懂。 安装 需要安装 Beego 和 Bee 的开发工具: $ go get github.com/astaxie/beego $ go get github.com/beego/bee  注意: beege和bee是两个概念。 beego是框架,bee是工具,是命令。 在安装Beego前,先确认是否将$GOPATH/bin写入GO环境中。 创建应用 创建一个名为webDemo的应用 $ bee new webDemo //创建一个web应用 $ bee api webDemo //创建一个api应用   编译运行

mysql explain介绍

走远了吗. 提交于 2021-01-05 02:47:55
<div id="blog_content" class="blog_content"> <div style="font-size: 14px;" class="iteye-blog-content-contain">mysql环境优化:<br><p>1.如果order by 没有利用到索引,那么将会出现fileSort,如果sort_buffer不够大,fileSort过程则需要使用临时文件 ,fileSort优化,主要通过调整环境来达到,如下<br>2.设置参数,优化order by 时可能出现的file sort:<br>将sort_buffer_size = 1M read_rnd_buffer_size = 1M<br>修改为sort_buffer_size = 16M read_rnd_buffer_size = 16M<br>避免order by 过程 进行fileSort排序过程临时文件的产生。从3秒->0.7秒左右<br>3.去掉distinct,因为distinct加order by,mysql将自动使用临时表<br>distinct的优化方式详见:http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html<br>4.修改jdbc的url,增加参数useServerPrepStmts

Golang 入门系列(十三)用Beego开发web应用

血红的双手。 提交于 2021-01-05 02:42:20
接着之前的内容,前面已经讲过很多Golang的基础语法,mysql的使用,redis的使用,也讲了orm框架,如何创建一个webapi 服务等等,感兴趣的可以看看以前的文章, https://www.cnblogs.com/zhangweizhong/category/1275863.html , 今天要来说一说,如何用beego开发web应用。 介绍 beego 是一个快速开发 Go 应用的 HTTP 框架,他可以用来快速开发 API、Web 及后端服务等各种应用,是一个 RESTful 的框架,同时也是一个关注度和使用量都比价高的开源项目。我认为它是go初学者比较容易上手的一门MVC Web框架。 它是由国内团队开发的开源框架,文档基本都是中文,简单易懂。 安装   需要安装 Beego 和 Bee 的开发工具: $ go get github.com/astaxie/beego $ go get github.com/beego/bee   注意: beege和bee是两个概念。beego是框架,bee是工具,是命令。 在安装Beego前,先确认是否将$GOPATH/bin写入GO环境中。 创建应用   创建一个名为webDemo的应用 $ bee new webDemo // 创建一个web应用 $ bee api webDemo // 创建一个api应用   编译运行  

聊聊zerolog的encoder

我的梦境 提交于 2021-01-05 00:23:52
序 本文主要研究一下zerolog的encoder encoder github.com/rs/zerolog@v1.20.0 /encoder.go type encoder interface { AppendArrayDelim(dst []byte) []byte AppendArrayEnd(dst []byte) []byte AppendArrayStart(dst []byte) []byte AppendBeginMarker(dst []byte) []byte AppendBool(dst []byte, val bool) []byte AppendBools(dst []byte, vals []bool) []byte AppendBytes(dst, s []byte) []byte AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte AppendEndMarker(dst []byte) []byte AppendFloat32(dst []byte, val

新型 Golang 蠕虫在服务器上投放 XMRig Miner 病毒

╄→尐↘猪︶ㄣ 提交于 2021-01-04 22:22:40
译者:知道创宇404实验室翻译组 原文链接: https://www.intezer.com/blog/research/new-golang-worm-drops-xmrig-miner-on-servers/ 介绍 12月初,我们发现了一种新的用Golang编写的蠕虫。该蠕虫延续了 Golang在2020年流行的多平台恶意软件趋势。 该蠕虫试图在网络中传播,以便大规模运行XMRig Miner。恶意软件同时针对Windows和Linux服务器,可以轻松地从一个平台转移到另一个平台。它的目标是面向公众的服务:密码较弱的MySQL、Tomcat管理面板和Jenkins。在较旧的版本中,该蠕虫还尝试利用WebLogic的最新漏洞:CVE-2020-14882。 在我们的分析过程中,攻击者不断更新C&C服务器上的蠕虫。这表明该蠕虫处于活跃状态,并且可能在将来的更新中针对其他弱配置的服务。 技术分析 该攻击使用三个文件:一个dropper脚本(bash或powershell)、一个Golang二进制蠕虫和一个XMRig Miner,所有这些文件都托管在同一C&C上。 目前,还未检测到ELF蠕虫二进制文件和bash dropper脚本。 图1显示了VirusTotal中的ELF蠕虫二进制检测结果。 图1:在VirusTotal

Go 并发基础

二次信任 提交于 2021-01-04 11:58:14
协程(Goroutine) 我们知道 Go 中,存在一个 defer 关键字用于修饰一个函数或者方法,使得该函数或者方法在返回前才会执行,也就说被延迟执行,但又一定会执行。但其实 Go 中也存在类似的异步,或者说多线程的概念,但在 Go 中不叫作线程,而是叫协程。 协程相对于线程来说,是一个非常轻量级的东西,它在一个程序中,可以启动很多个。协程也称为 goroutine。goroutine 被 Go runtime 所调度,这一点和线程不一样。也就是说,Go 语言的并发是由 Go 自己所调度的,自己决定同时执行多少个 goroutine,什么时候执行哪几个。这些对于我们开发者来说很透明,只需要在编码的时候告诉 Go 语言要启动几个 goroutine,至于如何调度执行,我们不用关心。 启动一个 goroutine 简单,Go 语言为我们提供了 go 关键字,相比其他编程语言简化了很多,如代码: func main () { go fmt.Println( "码疯窝在香嗝喱辣" ) fmt.Println( "I am main goroutine" ) time.Sleep(time.Second) } 这样就启动了一个 goroutine,用来调用 fmt.Println 函数,打印"码疯窝在香嗝喱辣",所以这段代码里,其实有两个 goroutine,一个是 main 函数启动的

2018 ACM-ICPC World Finals

送分小仙女□ 提交于 2021-01-04 09:37:35
先枚举所有的列长度 对于每种列长度,然后里面用dp算 #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; const int INF = 0x3f3f3f3f; char seq[85]; int Len[2505]; int mp[2][200005]; int has[200005]; int sufLen[2505]; int Get(int flag, int tmp, int cnt) { if(has[tmp] == cnt) return mp[flag][tmp]; else return 0; } int main() { int n; while(~scanf("%d", &n)) { // memset(mp, 0, sizeof(mp)); int ansCnt = -1; int ansPos; int maxLen = -1; int sumLen = 0; for(int i = 0; i < n; ++i) { scanf("%s", seq);