diff --git a/plugins/config/interface.go b/plugins/config/interface.go index 2d1e2b3..050faf7 100644 --- a/plugins/config/interface.go +++ b/plugins/config/interface.go @@ -13,17 +13,17 @@ type Configurer interface { // return err // } // } - UnmarshalKey(name string, out interface{}) error + UnmarshalKey(name string, out any) error // Unmarshal unmarshal the config into a Struct. Make sure that the tags // on the fields of the structure are properly set. - Unmarshal(out interface{}) error + Unmarshal(out any) error // Get used to get config section - Get(name string) interface{} + Get(name string) any // Overwrite used to overwrite particular values in the unmarshalled config - Overwrite(values map[string]interface{}) error + Overwrite(values map[string]any) error // Has checks if config section exists. Has(name string) bool diff --git a/plugins/jobs/pipeline/pipeline.go b/plugins/jobs/pipeline/pipeline.go index 9b63ecf..3b40eef 100644 --- a/plugins/jobs/pipeline/pipeline.go +++ b/plugins/jobs/pipeline/pipeline.go @@ -7,7 +7,7 @@ import ( ) // Pipeline defines pipeline options. -type Pipeline map[string]interface{} +type Pipeline map[string]any const ( priority string = "priority" @@ -20,12 +20,12 @@ const ( ) // With pipeline value -func (p *Pipeline) With(name string, value interface{}) { +func (p *Pipeline) With(name string, value any) { (*p)[name] = value } // Name returns pipeline name. -func (p Pipeline) Name() string { +func (p *Pipeline) Name() string { // https://github.com/spiral/roadrunner-jobs/blob/master/src/Queue/CreateInfo.php#L81 // In the PHP client library used the wrong key name // should be "name" instead of "queue" @@ -37,18 +37,18 @@ func (p Pipeline) Name() string { } // Driver associated with the pipeline. -func (p Pipeline) Driver() string { +func (p *Pipeline) Driver() string { return p.String(driver, "") } // Has checks if value presented in pipeline. -func (p Pipeline) Has(name string) bool { - if _, ok := p[name]; ok { +func (p *Pipeline) Has(name string) bool { + if _, ok := (*p)[name]; ok { return true } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if _, ok := rv[name]; ok { return true } @@ -61,15 +61,15 @@ func (p Pipeline) Has(name string) bool { } // String must return option value as string or return default value. -func (p Pipeline) String(name string, d string) string { - if value, ok := p[name]; ok { +func (p *Pipeline) String(name string, d string) string { + if value, ok := (*p)[name]; ok { if str, ok := value.(string); ok { return str } } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if rv[name] != "" { return rv[name].(string) } @@ -81,15 +81,15 @@ func (p Pipeline) String(name string, d string) string { } // Int must return option value as string or return default value. -func (p Pipeline) Int(name string, d int) int { - if value, ok := p[name]; ok { +func (p *Pipeline) Int(name string, d int) int { + if value, ok := (*p)[name]; ok { if i, ok := value.(int); ok { return i } } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if rv[name] != nil { return rv[name].(int) } @@ -101,8 +101,8 @@ func (p Pipeline) Int(name string, d int) int { } // Bool must return option value as bool or return default value. -func (p Pipeline) Bool(name string, d bool) bool { - if value, ok := p[name]; ok { +func (p *Pipeline) Bool(name string, d bool) bool { + if value, ok := (*p)[name]; ok { if i, ok := value.(string); ok { switch i { case "true": @@ -115,8 +115,8 @@ func (p Pipeline) Bool(name string, d bool) bool { } } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if rv[name] != nil { if i, ok := value.(string); ok { switch i { @@ -138,8 +138,8 @@ func (p Pipeline) Bool(name string, d bool) bool { // Map must return nested map value or empty config. // Here might be sqs attributes or tags for example -func (p Pipeline) Map(name string, out map[string]string) error { - if value, ok := p[name]; ok { +func (p *Pipeline) Map(name string, out map[string]string) error { + if value, ok := (*p)[name]; ok { if m, ok := value.(string); ok { err := json.Unmarshal(internal.AsBytes(m), &out) if err != nil { @@ -148,8 +148,8 @@ func (p Pipeline) Map(name string, out map[string]string) error { } } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if val, ok := rv[name]; ok { if m, ok := val.(string); ok { err := json.Unmarshal(internal.AsBytes(m), &out) @@ -167,15 +167,15 @@ func (p Pipeline) Map(name string, out map[string]string) error { } // Priority returns default pipeline priority -func (p Pipeline) Priority() int64 { - if value, ok := p[priority]; ok { +func (p *Pipeline) Priority() int64 { + if value, ok := (*p)[priority]; ok { if v, ok := value.(int64); ok { return v } } else { // check the config section if exists - if val, ok := p[config]; ok { - if rv, ok := val.(map[string]interface{}); ok { + if val, ok := (*p)[config]; ok { + if rv, ok := val.(map[string]any); ok { if rv[name] != nil { return rv[name].(int64) } @@ -185,3 +185,7 @@ func (p Pipeline) Priority() int64 { return 10 } + +func (p *Pipeline) Get(key string) any { + return (*p)[key] +} diff --git a/plugins/rpc/interface.go b/plugins/rpc/interface.go index eb6da9a..e156493 100644 --- a/plugins/rpc/interface.go +++ b/plugins/rpc/interface.go @@ -3,5 +3,5 @@ package rpc // RPCer declares the ability to create set of public RPC methods. type RPCer interface { // RPC Provides methods for the given service. - RPC() interface{} + RPC() any } diff --git a/plugins/server/interface.go b/plugins/server/interface.go index 5e44c83..58d51ab 100644 --- a/plugins/server/interface.go +++ b/plugins/server/interface.go @@ -16,5 +16,5 @@ type Server interface { // NewWorker return a new worker with provided and attached by the user listeners and environment variables NewWorker(ctx context.Context, env map[string]string) (worker.BaseProcess, error) // NewWorkerPool return new pool of workers (PHP) with attached events listeners, env variables and based on the provided configuration - NewWorkerPool(ctx context.Context, config interface{}, env map[string]string, log *zap.Logger) (pool.Pool, error) + NewWorkerPool(ctx context.Context, config any, env map[string]string, log *zap.Logger) (pool.Pool, error) } diff --git a/pool/pool.go b/pool/pool.go index e203f10..1d65132 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -10,7 +10,7 @@ import ( // Pool managed set of inner worker processes. type Pool interface { // GetConfig returns pool configuration. - GetConfig() interface{} + GetConfig() any // Exec executes task with payload Exec(rqs *payload.Payload) (*payload.Payload, error)