Skip to content

Commit

Permalink
chore: replace interface{} with any
Browse files Browse the repository at this point in the history
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
  • Loading branch information
rustatian committed Aug 4, 2022
1 parent eca70bd commit fcb1d78
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 35 deletions.
8 changes: 4 additions & 4 deletions plugins/config/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 32 additions & 28 deletions plugins/jobs/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// Pipeline defines pipeline options.
type Pipeline map[string]interface{}
type Pipeline map[string]any

const (
priority string = "priority"
Expand All @@ -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"
Expand All @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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":
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -185,3 +185,7 @@ func (p Pipeline) Priority() int64 {

return 10
}

func (p *Pipeline) Get(key string) any {
return (*p)[key]
}
2 changes: 1 addition & 1 deletion plugins/rpc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion plugins/server/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fcb1d78

Please sign in to comment.