I’m using IRIS MVC for the API, but all the numbers in the data I’m returning are scientific notation: 3e5 and stuff like that
Let’s see how it works
func NewDefault(a) *iris.Application {
app := iris.New()
app.Logger().SetLevel("Debug")
// Set the path
pathToAccessLog := "./log/access_log.%Y%m%d%H%M"
// Set how long to split a file
w, err := rotatelogs.New(
pathToAccessLog,
rotatelogs.WithMaxAge(24*time.Hour),
rotatelogs.WithRotationTime(time.Hour))
iferr ! =nil {
panic(fmt.Sprintf("rotate logs setup failure: %s", err))
}
ac := accesslog.New(w)
ac.ResponseBody = true
// Set the output to the console
ac.AddOutput(app.Logger().Printer)
// Application middleware
app.UseRouter(ac.Handler)
// Register the recovery, after accesslog and recover,
// before end-developer's middleware.
app.UseRouter(recover.New())
app.UseRouter(cors.AllowAll())
app.Validator = validator.NewValidator()
return app
}
func Run(port string) {
app := commonctrl.NewDefault()
mvcApp := mvc.New(app)
mvcApp.Party("auth").Handle(new(AuthController))
iferr := app.Listen(port, iris.WithOptimizations); err ! =nil {
_, _ = fmt.Fprintf(os.Stderr, "user service start failure: %s\n", err)
return}}Copy the code
Expectations and Results
{“code”:0,”msg”:”success”,”data”:1619568000}
Actual results
{“code”:0,”msg”:”success”,”data”:1619568e30}
The solution
Accesslog set BodyMinify = true
ac.BodyMinify = true
Copy the code
why
Accesslog sets ResponseBody=true after the middleware reads or writes the value returned
When iris writes json, it can set parameters to default camel name, null value omission, etc. Accesslog will process this when it reads ResponseBody