
Go
文章平均质量分 65
Go相关技术博客
zzy979
这个作者很懒,什么都没留下…
展开
-
net/http包源码解读
使用net/http包编写一个最简单的Web服务器: package main import ( "fmt" "log" "net/http" ) func main() { http.HandleFunc("/", index) log.Fatal(http.ListenAndServe("localhost:8000", nil)) } func index(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello,原创 2021-06-30 20:04:12 · 521 阅读 · 0 评论 -
gomock使用教程
gomock是Go官方提供的模拟(mock)框架 mockgen工具用于针对接口生成mock对象代码 GitHub仓库:https://github.com/golang/mock 安装 go get github.com/golang/mock/gomock go get github.com/golang/mock/mockgen 安装完成后可以在命令行中直接使用mockgen命令(需要将$GOPATH/bin添加到PATH环境变量) 示例 假设foo/foo.go中定义了一个接口Foo和一个函数Ba原创 2021-06-20 18:02:21 · 2421 阅读 · 0 评论 -
Go智障的时间格式化
time.Time类型的Format()方法将时间格式化为字符串,但该方法的参数必须用一个固定的参考时间"2006-01-02 15:04:05" 用其他时间会得到奇怪的结果 package main import ( "fmt" "time" ) func main() { t := time.Date(2021, 5, 24, 18, 50, 40, 0, time.Local) fmt.Println(t) fmt.Println(t.Format("2006-01-02 15:04:0原创 2021-06-11 15:40:52 · 362 阅读 · 1 评论