mirror of
https://gitee.com/johng/gf.git
synced 2024-11-29 18:57:44 +08:00
add example for ctx keys feature of package glog
(#3273)
This commit is contained in:
parent
f919f90bf5
commit
383937fe69
4
example/os/log/ctx_keys/config.yaml
Normal file
4
example/os/log/ctx_keys/config.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
logger:
|
||||
Level: "all"
|
||||
Stdout: true
|
||||
CtxKeys: ["RequestId", "UserId"]
|
20
example/os/log/ctx_keys/main.go
Normal file
20
example/os/log/ctx_keys/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var ctx = context.Background()
|
||||
ctx = context.WithValue(ctx, "RequestId", "123456789")
|
||||
ctx = context.WithValue(ctx, "UserId", "10000")
|
||||
g.Log().Error(ctx, "runtime error")
|
||||
}
|
@ -193,6 +193,7 @@ func (v *Validator) doCheckValue(ctx context.Context, in doCheckValueInput) Erro
|
||||
}
|
||||
// The error should have error code that is `gcode.CodeValidationFailed`.
|
||||
if gerror.Code(err) == gcode.CodeNil {
|
||||
// TODO it's better using interface?
|
||||
if e, ok := err.(*gerror.Error); ok {
|
||||
e.SetCode(gcode.CodeValidationFailed)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user