diff --git a/example/os/log/ctx_keys/config.yaml b/example/os/log/ctx_keys/config.yaml new file mode 100644 index 00000000000..80f8fc3024f --- /dev/null +++ b/example/os/log/ctx_keys/config.yaml @@ -0,0 +1,4 @@ +logger: + Level: "all" + Stdout: true + CtxKeys: ["RequestId", "UserId"] \ No newline at end of file diff --git a/example/os/log/ctx_keys/main.go b/example/os/log/ctx_keys/main.go new file mode 100644 index 00000000000..fcb4875a8fe --- /dev/null +++ b/example/os/log/ctx_keys/main.go @@ -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") +} diff --git a/util/gvalid/gvalid_validator_check_value.go b/util/gvalid/gvalid_validator_check_value.go index 8647f83a844..dabd4a634fe 100644 --- a/util/gvalid/gvalid_validator_check_value.go +++ b/util/gvalid/gvalid_validator_check_value.go @@ -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) }