diff options
author | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-09-16 17:12:37 +0300 |
commit | f3491c089b4da77fd8d2bc942a88b6b8d117a8a5 (patch) | |
tree | 32bfffb1f24eeee7b909747cc00a6a6b9fd3ee83 /plugins/websockets/config.go | |
parent | 5d2cd55ab522d4f1e65a833f91146444465a32ac (diff) |
Move plugins to a separate repository
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/websockets/config.go')
-rw-r--r-- | plugins/websockets/config.go | 83 |
1 files changed, 0 insertions, 83 deletions
diff --git a/plugins/websockets/config.go b/plugins/websockets/config.go deleted file mode 100644 index 933a12e0..00000000 --- a/plugins/websockets/config.go +++ /dev/null @@ -1,83 +0,0 @@ -package websockets - -import ( - "strings" - "time" - - "github.com/spiral/errors" - "github.com/spiral/roadrunner/v2/pkg/pool" -) - -/* -websockets: - broker: default - allowed_origin: "*" - path: "/ws" -*/ - -// Config represents configuration for the ws plugin -type Config struct { - // http path for the websocket - Path string `mapstructure:"path"` - AllowedOrigin string `mapstructure:"allowed_origin"` - Broker string `mapstructure:"broker"` - - // wildcard origin - allowedWOrigins []wildcard - allowedOrigins []string - allowedAll bool - - // Pool with the workers for the websockets - Pool *pool.Config `mapstructure:"pool"` -} - -// InitDefault initialize default values for the ws config -func (c *Config) InitDefault() error { - if c.Path == "" { - c.Path = "/ws" - } - - // broker is mandatory - if c.Broker == "" { - return errors.Str("broker key should be specified") - } - - if c.Pool == nil { - c.Pool = &pool.Config{} - if c.Pool.NumWorkers == 0 { - // 2 workers by default - c.Pool.NumWorkers = 2 - } - - if c.Pool.AllocateTimeout == 0 { - c.Pool.AllocateTimeout = time.Minute - } - - if c.Pool.DestroyTimeout == 0 { - c.Pool.DestroyTimeout = time.Minute - } - if c.Pool.Supervisor != nil { - c.Pool.Supervisor.InitDefaults() - } - } - - if c.AllowedOrigin == "" { - c.AllowedOrigin = "*" - } - - // Normalize - origin := strings.ToLower(c.AllowedOrigin) - if origin == "*" { - // If "*" is present in the list, turn the whole list into a match all - c.allowedAll = true - return nil - } else if i := strings.IndexByte(origin, '*'); i >= 0 { - // Split the origin in two: start and end string without the * - w := wildcard{origin[0:i], origin[i+1:]} - c.allowedWOrigins = append(c.allowedWOrigins, w) - } else { - c.allowedOrigins = append(c.allowedOrigins, origin) - } - - return nil -} |