随笔分类 - golang
摘要:原因是move命令是cmd里带的。没有单独的exe文件在PATH文件夹里。 这样写: cmds: - cmd /c move "./aaa/bbb/1.txt" "./ccc/ddd/2.txt" 其他的比如copy等命令同理。。。
阅读全文
摘要:引入pprof _ "net/http/pprof" 启动pprof go func() { http.ListenAndServe("0.0.0.0:6060", nil) }() 命令行输入 go tool pprof --text http://127.0.0.1:6060/debug/ppr
阅读全文
摘要:gorm中,在使用joins()时,如果直接预加载结构体的key键,是不能指定要查询的字段的,会调用所有,所以要这样写(伪代码): db.Select("user.id AS User__id").Joins("left join user ON userid = user.id") 注意as那里,
阅读全文
摘要:在使用jet引擎时,提示 import错误。 这里有个坑,{{import “../file”}} 类似这样的命令,必须放到第一行。。。 不知道是jet的坑,还是gofiber的坑。。
阅读全文
摘要:go程序默认打包时,会携带一些系统路径,可以通过这个命令去掉 go build -trimpath 好像时1.13之后才有的参数。
阅读全文
摘要:其他基于fasthttp的也可以,golang自带的http server也一样的原理。 new 一个新的router,然后把老的handler = 新的handler server := APP.Server() server.Handler = NewRouter().Handler() APP
阅读全文
摘要:很简单,但是网上好像没什么人提到: time.Now().Format(time.RFC3339) 生成效果直接就是: 2020-08-10T20:52:07+08:00 记录下来,方便其他人查找吧
阅读全文
摘要:Each():用来遍历标签,对子标签进行处理。 EachWithBreak():和Each类似,都是用来遍历标签的。区别是EachWithBreak接收的函数有一个返回值bool,返回false会立刻结束当前遍历。 Map():Map内部的返回值是string,所以整体会返回一个string集合。
阅读全文
摘要:不废话,直接上代码 import ( "bytes" "compress/gzip" ) func main(){ data := []byte(hello world) gzipCompress(&data) } func gzipCompress(content *[]byte) []byte
阅读全文
摘要:首先定义一个context 中间件: package middleware import ( "context" "fmt" "net/http" "strings" ) // ContextValue is a context key type ContextValue map[string]in
阅读全文
摘要:没有太多需要解释的,直接给出代码: db.SetLogger(Logger{}) type Logger struct { } func (logger Logger) Print(values ...interface{}) { fmt.Println(values...) // 这里输出的就是日
阅读全文
摘要:import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/os/glog" ) func main() { glog.SetDebug(false) // 关闭debug信息 s := g.Server() s.SetDumpRouterMa
阅读全文

浙公网安备 33010602011771号