blog-service icon indicating copy to clipboard operation
blog-service copied to clipboard

《Go 语言编程之旅:一起用 Go 做项目》第二章:博客程序(HTTP Server)

Results 28 blog-service issues
Sort by recently updated
recently updated
newest added

测试方式: ab -c 10 -n 100 localhost:8000/debug/vars 测试结果: ``` fatal error: concurrent map read and map write goroutine 139 [running]: runtime.throw(0x4a46303, 0x21) /usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc001b0c208 sp=0xc001b0c1d8 pc=0x4034962 runtime.mapaccess2(0x491bee0, 0xc0005cb080, 0xc001b0c288,...

hello, There is a spelling error here. File:internal/middleware/recovery.go:17:defailtMailer->defaultMailer

按照书上的代码,我可以监听到热更新,接着我想测试一下是否可用。 我把runmode从debug改成了test,当我访问一个接口的时候控制台仍然会有logger输出,也就是说gin的模式并没有被更新。 我在想是不是调用了reloadallsection这个方法的时候,只是把global里的变量改了。 类似的情况还可以比如说更改端口号,更改数据库密码等等。都是只能监听到这些值的更新,但并没有影响到程序,还是得重启一遍才生效。 请大神们指点一下。

我是在get tags里面返回response之前,加上了一个time.Sleep(10 * time.Second) ,然后在yaml里面设置的时间是1s,但是没有生效啊

删除 switch case 中的 break

在使用 http://127.0.0.1:8000/api/v1/tags?state=6 时候 global.Logger.Errorf(c, "app.BindAndValid errs: %v", errs)这行 panic err: Key "X-Trace-ID" does not exist

配置文件热更新后,对于某些已使用的地方是无效的 main.go ``` // 对于以下变量即使global.ServerSetting发生变化也是不会更新的 gin.SetMode(global.ServerSetting.RunMode) router := routers.NewRouter() s := &http.Server{ Addr: ":" + global.ServerSetting.HttpPort, Handler: router, ReadTimeout: global.ServerSetting.ReadTimeout, WriteTimeout: global.ServerSetting.WriteTimeout, MaxHeaderBytes: 1

withCaller() 的调用现在放在 mian.setupLogger 函数里,导致不管怎么打印,日志里的 callers 字段的值都是指向 main.init 函数。 我自己挪到了 Logger.Output 函数里 ![image](https://user-images.githubusercontent.com/15248446/101602134-965a1e00-3a38-11eb-837e-657cd96b84f5.png)

```go package routers import ( "github.com/gin-gonic/gin" v1 "github.com/qiuyuhome/go-gin-blog-api/internal/routers/api/v1" ) func NewRouter() *gin.Engine { r := gin.New() r.Use(gin.Logger()) r.Use(gin.Recovery()) article := v1.NewArticle() tag := v1.NewTag() apiv1 := r.Group("/api/v1") // todo, 下面的...

修复middleware中的translations中间件在压测下报[map线程安全的问题](https://github.com/go-programming-tour-book/blog-service/issues/20) 主要是注册翻译器主要是在validator的[map](https://github.com/go-playground/validator/blob/ce34f361cca51e25715399ab801c5e1c01d02d89/validator_instance.go#L294)中注册的 所以只用注册一次就够了 后面翻译验证错误时 拿出原本存在global的universal-translator即可复用之前用于注册的Translator