5 Commits

Author SHA1 Message Date
8881bf58e7 Merge pull request 'update err not found arg' (#46) from errors into master
All checks were successful
Go Action / goaction (push) Successful in 1m25s
Reviewed-on: #46
2026-01-06 16:07:23 +03:00
89f664c268 update err not found arg
All checks were successful
Go Action / goaction (pull_request) Successful in 1m29s
2026-01-06 16:05:24 +03:00
190950aca0 Merge pull request 'update configure providers' (#45) from configure into master
All checks were successful
Go Action / goaction (push) Successful in 55s
Reviewed-on: #45
2026-01-06 12:54:55 +03:00
be9e0cd8c8 update etcd prov
All checks were successful
Go Action / goaction (pull_request) Successful in 54s
2026-01-06 12:46:00 +03:00
a4c9c10a2d update configure providers
All checks were successful
Go Action / goaction (pull_request) Successful in 1m3s
2026-01-06 12:30:08 +03:00
11 changed files with 138 additions and 18 deletions

View File

@@ -44,10 +44,10 @@ type BindProvider interface {
Bind(ctx context.Context, data Variables) error
}
type DunpProvider interface {
type DumpProvider interface {
Provider
DumpRefernce(ctx context.Context, w io.Writer, opts Options) error
DumpReference(ctx context.Context, w io.Writer, opts Options) error
}
type Providers interface {

View File

@@ -10,12 +10,12 @@ func Default(in any) param.Option {
return option.Default(value.New(in))
}
func Required(v param.Params) {
option.Required(v)
func Required(v param.Params) param.Params {
return option.Required(v)
}
func Slice(v param.Params) {
option.Slice(v)
func Slice(v param.Params) param.Params {
return option.Slice(v)
}
func String(name, description string, opts ...param.Option) option.Option {

View File

@@ -2,6 +2,7 @@ package arg
import (
"context"
"errors"
"fmt"
"io"
"os"
@@ -18,6 +19,12 @@ const (
doubleDash = `--`
defaultLenLognOption = 2
dash = `-`
Name = "arg"
)
var (
_ config.DumpProvider = (*Argv)(nil)
_ config.BindProvider = (*Argv)(nil)
)
// Deprecated: use WithArgs.
@@ -46,11 +53,18 @@ func WithArgs(args []string) func(*Argv) {
}
}
func WithName(name string) func(*Argv) {
return func(a *Argv) {
a.name = name
}
}
func New(opts ...func(*Argv)) *Argv {
arg := &Argv{
args: os.Args[1:],
pos: 0,
Map: memory.Map{},
name: Name,
}
for _, opt := range opts {
@@ -65,6 +79,7 @@ type Argv struct {
args []string
pos uint64
name string
}
func (i *Argv) Value(ctx context.Context, key ...string) (config.Value, error) {
@@ -116,7 +131,11 @@ func (i *Argv) Bind(ctx context.Context, def config.Variables) error {
return nil
}
func (i *Argv) DumpRefernce(_ context.Context, w io.Writer, opt config.Options) error {
func (i *Argv) Name() string {
return i.name
}
func (i *Argv) DumpReference(_ context.Context, w io.Writer, opt config.Options) error {
return NewDump().Reference(w, opt)
}
@@ -199,7 +218,21 @@ func (i *Argv) parseShortOption(arg string, def config.Variables) error {
func (i *Argv) parseArgument(arg string, def config.Variables) error {
opt, err := def.ByParam(PosArgument(i.pos))
if err != nil {
return fmt.Errorf("%w", err)
var maxArgs uint64
if i.pos > 0 {
maxArgs -= i.pos
}
if errors.Is(err, config.ErrNotFound) {
return fmt.Errorf("argument[%s] by pos[%d] max[%d]: %w",
arg,
i.pos+1,
maxArgs,
config.ErrNotFound,
)
}
return fmt.Errorf("find argiment by pos[%d] max[%d]: %w", i.pos+1, maxArgs, err)
}
i.pos++

View File

@@ -34,7 +34,7 @@ func (c chain) Bind(ctx context.Context, def config.Variables) error {
for _, input := range c {
if prov, ok := input.(config.BindProvider); ok {
if err := prov.Bind(ctx, def); err != nil {
return fmt.Errorf("%T:%w", input, err)
return fmt.Errorf("prov[%s]:%w", input.Name(), err)
}
}
}

View File

@@ -15,7 +15,10 @@ import (
const Name = "env"
var _ config.Provider = (*Provider)(nil)
var (
_ config.Provider = (*Provider)(nil)
_ config.DumpProvider = (*Provider)(nil)
)
type Option func(*Provider)
@@ -23,13 +26,25 @@ func WithKeyFactory(factory func(...string) string) Option {
return func(p *Provider) { p.key = factory }
}
func WithName(name string) Option {
return func(p *Provider) {
p.name = name
}
}
func WithPrefix(prefix string) Option {
return func(p *Provider) {
p.prefix = prefix
}
}
func New(namespace, appName string, opts ...Option) *Provider {
provider := Provider{
key: func(path ...string) string {
return strings.ToUpper(strings.Join(path, "_"))
},
prefix: strings.ToUpper(namespace + "_" + appName + "_"),
name: "",
name: Name,
}
for _, opt := range opts {

View File

@@ -27,10 +27,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
gitoa.ru/go-4devs/config v0.0.1 h1:9KrOO09YbIMO8qL8aVn/G74DurGdOIW5y3O02bays4I=
gitoa.ru/go-4devs/config v0.0.1/go.mod h1:xfEC2Al9xnMLJUuekYs3KhJ5BIzWAseNwkMwbN6/xss=
gitoa.ru/go-4devs/config v0.0.2 h1:bkTxW57kDDMf4cj/8W7fxPSN7JCPWEqlhCmL6LP3Vzg=
gitoa.ru/go-4devs/config v0.0.2/go.mod h1:xfEC2Al9xnMLJUuekYs3KhJ5BIzWAseNwkMwbN6/xss=
gitoa.ru/go-4devs/config v0.0.3 h1:+ecwDQj4fneJCh2uLNNAonm4cUJdGmlfxUsFhQRI9Ko=
gitoa.ru/go-4devs/config v0.0.3/go.mod h1:UINWnObZA0nLiJro+TtavUBBvN0cSt17aRHOk20pP74=
go.etcd.io/etcd/api/v3 v3.5.11 h1:B54KwXbWDHyD3XYAwprxNzTe7vlhR69LuBgZnMVvS7E=

View File

@@ -27,7 +27,31 @@ type Client interface {
client.Watcher
}
func New(namespace, appName string, client Client) *Provider {
func WithName(name string) func(*Provider) {
return func(p *Provider) {
p.name = name
}
}
func WithLog(fn func(context.Context, string, ...any)) func(*Provider) {
return func(p *Provider) {
p.log = fn
}
}
func WithPrefix(prefix string) func(*Provider) {
return func(p *Provider) {
p.prefix = prefix
}
}
func WithKey(fn func(...string) string) func(*Provider) {
return func(p *Provider) {
p.key = fn
}
}
func New(namespace, appName string, client Client, opts ...func(*Provider)) *Provider {
prov := Provider{
client: client,
key: func(s ...string) string {
@@ -40,6 +64,10 @@ func New(namespace, appName string, client Client) *Provider {
},
}
for _, opt := range opts {
opt(&prov)
}
return &prov
}

View File

@@ -17,8 +17,20 @@ const (
var _ config.Provider = (*Provider)(nil)
func New(data *ini.File) *Provider {
return &Provider{
func WithName(name string) func(*Provider) {
return func(p *Provider) {
p.name = name
}
}
func WithResolve(fn func([]string) (string, string)) func(*Provider) {
return func(p *Provider) {
p.resolve = fn
}
}
func New(data *ini.File, opts ...func(*Provider)) *Provider {
prov := &Provider{
data: data,
resolve: func(path []string) (string, string) {
if len(path) == 1 {
@@ -29,6 +41,12 @@ func New(data *ini.File) *Provider {
},
name: Name,
}
for _, opt := range opts {
opt(prov)
}
return prov
}
type Provider struct {

View File

@@ -19,6 +19,18 @@ const (
var _ config.Provider = (*Provider)(nil)
func WithKey(fn func(...string) string) Option {
return func(p *Provider) {
p.key = fn
}
}
func WithName(name string) Option {
return func(p *Provider) {
p.name = name
}
}
func New(json []byte, opts ...Option) *Provider {
provider := Provider{
key: func(s ...string) string {

View File

@@ -26,6 +26,18 @@ func WithSecretResolve(f func(key []string) (string, string)) SecretOption {
return func(s *Provider) { s.resolve = f }
}
func WithName(name string) SecretOption {
return func(p *Provider) {
p.name = name
}
}
func WithPrefix(prefix string) SecretOption {
return func(p *Provider) {
p.prefix = prefix
}
}
func New(namespace, appName string, client *api.Client, opts ...SecretOption) *Provider {
prov := Provider{
client: client,

View File

@@ -17,6 +17,12 @@ const (
var _ config.Provider = (*Provider)(nil)
func WithName(name string) Option {
return func(p *Provider) {
p.name = name
}
}
func NewFile(name string, opts ...Option) (*Provider, error) {
in, err := os.ReadFile(name)
if err != nil {