Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #10 Co-authored-by: andrey <andrey@4devs.io> Co-committed-by: andrey <andrey@4devs.io>
34 lines
952 B
Cheetah
34 lines
952 B
Cheetah
// read{{.FuncName}} {{.Description}}.
|
|
func (i {{.StructName}}) read{{.FuncName}}(ctx context.Context) (v {{.Type}},e error) {
|
|
val, err := i.Value(ctx, {{ .ParentKeys }}"{{ .Name }}")
|
|
if err != nil {
|
|
{{if .HasDefault}}
|
|
{{$default := .Default}}
|
|
{{range .DefaultErrors}}
|
|
if errors.Is(err,{{.}}){
|
|
return {{$default}}
|
|
}
|
|
{{end}}
|
|
{{end}}
|
|
return v, fmt.Errorf("read {{.Keys}}:%w",err)
|
|
}
|
|
|
|
{{.Parse "val" "v" .Keys }}
|
|
}
|
|
|
|
// Read{{.FuncName}} {{.Description}}.
|
|
func (i {{.StructName}}) Read{{.FuncName}}(ctx context.Context) ({{.Type}}, error) {
|
|
return i.read{{.FuncName}}(ctx)
|
|
}
|
|
|
|
// {{.FuncName}} {{.Description}}.
|
|
func (i {{.StructName}}) {{.FuncName}}({{if .Context}} ctx context.Context {{end}}) {{.Type}} {
|
|
{{if not .Context}} ctx := context.Background() {{end}}
|
|
val, err := i.read{{.FuncName}}(ctx)
|
|
if err != nil {
|
|
i.log(ctx, "get {{.Keys}}: %v", err)
|
|
}
|
|
|
|
return val
|
|
}
|