Merge pull request 'update config options' (#38) from dump-reference into master
All checks were successful
Go Action / goaction (push) Successful in 1m1s

Reviewed-on: #38
This commit was merged in pull request #38.
This commit is contained in:
2026-01-03 17:32:29 +03:00
6 changed files with 24 additions and 25 deletions

View File

@@ -5,7 +5,7 @@ import (
"gitoa.ru/go-4devs/config/param"
)
var _ config.Group = (*Definition)(nil)
var _ config.Options = (*Definition)(nil)
func New(opts ...config.Option) *Definition {
return &Definition{
@@ -28,10 +28,6 @@ func (d *Definition) Options() []config.Option {
return d.options
}
func (d *Definition) Name() string {
return ""
}
func (d *Definition) With(params param.Params) *Definition {
def := &Definition{
options: make([]config.Option, len(d.options)),

View File

@@ -19,7 +19,7 @@ func main() {
func run(f io.Writer) error {
ctx := context.Background()
defs:=make([]config.Group,0)
defs:=make([]config.Options,0)
{{ range .Configure }}
params{{.}} := param.New(
{{- if $.SkipContext }}view.WithSkipContext,{{ end }}

View File

@@ -21,7 +21,7 @@ var tpls embed.FS
var initTpl = template.Must(template.New("tpls").ParseFS(tpls, "tpl/*.tpl")).Lookup("init.go.tpl")
func Run(_ context.Context, fullPkg string, w io.Writer, defs ...config.Group) error {
func Run(_ context.Context, fullPkg string, w io.Writer, defs ...config.Options) error {
data := Data{
Packages: pkg.NewImports(fullPkg).
Adds("fmt", "context", "gitoa.ru/go-4devs/config"),

View File

@@ -66,7 +66,7 @@ func WithParent(in *View) Option {
}
}
func NewViews(option config.Group, opts ...Option) View {
func NewViews(option config.Options, opts ...Option) View {
view := newView(option, opts...)
for _, op := range option.Options() {
@@ -76,11 +76,9 @@ func NewViews(option config.Group, opts ...Option) View {
return view
}
type IOption any
func newView(option config.Option, opts ...Option) View {
func newView(params param.Params, opts ...Option) View {
vi := View{
Option: option,
Params: params,
parent: nil,
children: nil,
}
@@ -105,7 +103,7 @@ func NewView(opt config.Option, opts ...Option) View {
}
type View struct {
config.Option
param.Params
children []View
parent *View
@@ -125,7 +123,7 @@ func (v View) Types() []any {
}
func (v View) Kind() reflect.Type {
return reflect.TypeOf(v.Option)
return reflect.TypeOf(v.Params)
}
func (v View) Views() []View {
@@ -133,7 +131,7 @@ func (v View) Views() []View {
}
func (v View) Param(key any) string {
data, has := v.Option.Param(key)
data, has := v.Params.Param(key)
if has {
return fmt.Sprintf("%v", data)
}
@@ -156,7 +154,7 @@ func (v View) ClildSkipContext() bool {
}
func (v View) SkipContext() bool {
if IsSkipContext(v.Option) {
if IsSkipContext(v.Params) {
return true
}
@@ -168,7 +166,11 @@ func (v View) SkipContext() bool {
}
func (v View) Name() string {
return v.Option.Name()
if data, ok := v.Params.(interface{ Name() string }); ok {
return data.Name()
}
return ""
}
func (v View) Keys() []string {
@@ -177,7 +179,7 @@ func (v View) Keys() []string {
keys = append(keys, v.parent.Keys()...)
}
if name := v.Option.Name(); name != "" {
if name := v.Name(); name != "" {
keys = append(keys, name)
}
@@ -185,11 +187,11 @@ func (v View) Keys() []string {
}
func (v View) Type() any {
return param.Type(v.Option)
return param.Type(v.Params)
}
func (v View) FuncName() string {
data, ok := v.Option.Param(viewParamFunctName)
data, ok := v.Params.Param(viewParamFunctName)
name, valid := data.(string)
if !ok || !valid {
@@ -200,7 +202,7 @@ func (v View) FuncName() string {
}
func (v View) StructName() string {
name, ok := param.String(v.Option, viewParamStructName)
name, ok := param.String(v.Params, viewParamStructName)
if ok {
return name
}
@@ -231,11 +233,11 @@ func (v View) ParentStruct() string {
}
func (v View) Description() string {
return param.Description(v.Option)
return param.Description(v.Params)
}
func (v View) Default() any {
data, ok := option.DataDefaut(v.Option)
data, ok := option.DataDefaut(v.Params)
if !ok {
return nil
}
@@ -244,5 +246,5 @@ func (v View) Default() any {
}
func (v View) HasDefault() bool {
return option.HasDefaut(v.Option)
return option.HasDefaut(v.Params)
}

View File

@@ -34,6 +34,7 @@ type Group interface {
type Options interface {
Options() []Option
param.Params
}
type BindProvider interface {

View File

@@ -99,7 +99,7 @@ func testVariables(t *testing.T) config.Variables {
),
)
return config.NewVars(def)
return config.NewVars(def.Options()...)
}
type Duration struct {