diff --git a/lib/gat/handlers/pool/pools/basic/config.go b/lib/gat/handlers/pool/pools/basic/config.go index 626257a35b590b3279073aa8ff24f529832f30fc..0af680c37e5322f2ede3bb17a0739322b09f6653 100644 --- a/lib/gat/handlers/pool/pools/basic/config.go +++ b/lib/gat/handlers/pool/pools/basic/config.go @@ -62,6 +62,9 @@ type Config struct { // TrackedParameters are parameters which should be synced by updating the server, not the client. TrackedParameters []strutil.CIString `json:"tracked_parameters,omitempty"` + RawCritics []json.RawMessage `json:"critics,omitempty" caddy:"namespace=pggat.handlers.pool.critics inline_key=critic"` + Critics []pool.Critic `json:"-"` + Logger *zap.Logger `json:"-"` } @@ -75,6 +78,8 @@ func (T Config) Spool() spool.Config { ReconnectInitialTime: time.Duration(T.ServerReconnectInitialTime), ReconnectMaxTime: time.Duration(T.ServerReconnectMaxTime), + Critics: T.Critics, + Logger: T.Logger, } } diff --git a/lib/gat/handlers/pool/pools/basic/factory.go b/lib/gat/handlers/pool/pools/basic/factory.go index be4a059443a713a11702136c4a8cf75383b0d92a..44d58c95954b33d12d7a4c53e419eb06e884aa1a 100644 --- a/lib/gat/handlers/pool/pools/basic/factory.go +++ b/lib/gat/handlers/pool/pools/basic/factory.go @@ -1,6 +1,8 @@ package basic import ( + "fmt" + "github.com/caddyserver/caddy/v2" "gfx.cafe/gfx/pggat/lib/gat/handlers/pool" @@ -26,6 +28,19 @@ func (T *Factory) CaddyModule() caddy.ModuleInfo { func (T *Factory) Provision(ctx caddy.Context) error { T.Logger = ctx.Logger() + if T.RawCritics != nil { + raw, err := ctx.LoadModule(T, "RawCritics") + if err != nil { + return fmt.Errorf("loading critic module: %v", err) + } + + val := raw.([]any) + T.Critics = make([]pool.Critic, 0, len(val)) + for _, vv := range val { + T.Critics = append(T.Critics, vv.(pool.Critic)) + } + } + raw, err := ctx.LoadModule(T, "RawPoolerFactory") if err != nil { return err diff --git a/lib/gat/handlers/pool/pools/hybrid/config.go b/lib/gat/handlers/pool/pools/hybrid/config.go index 4253c6264e3f59b3358324193c11ccb98b0e67f7..0b53ce2f2fe80204274a47f49c4a724dd87599d5 100644 --- a/lib/gat/handlers/pool/pools/hybrid/config.go +++ b/lib/gat/handlers/pool/pools/hybrid/config.go @@ -1,11 +1,13 @@ package hybrid import ( + "encoding/json" "time" "github.com/caddyserver/caddy/v2" "go.uber.org/zap" + "gfx.cafe/gfx/pggat/lib/gat/handlers/pool" "gfx.cafe/gfx/pggat/lib/gat/handlers/pool/poolers/rob" "gfx.cafe/gfx/pggat/lib/gat/handlers/pool/spool" "gfx.cafe/gfx/pggat/lib/util/strutil" @@ -19,6 +21,9 @@ type Config struct { TrackedParameters []strutil.CIString `json:"tracked_parameters,omitempty"` + RawCritics []json.RawMessage `json:"critics,omitempty" caddy:"namespace=pggat.handlers.pool.critics inline_key=critic"` + Critics []pool.Critic `json:"-"` + Logger *zap.Logger `json:"-"` } @@ -31,6 +36,8 @@ func (T Config) Spool() spool.Config { ReconnectInitialTime: time.Duration(T.ServerReconnectInitialTime), ReconnectMaxTime: time.Duration(T.ServerReconnectMaxTime), + Critics: T.Critics, + Logger: T.Logger, } } diff --git a/lib/gat/handlers/pool/pools/hybrid/factory.go b/lib/gat/handlers/pool/pools/hybrid/factory.go index 3feae210cfc0da65ff1b71b25bed574a92b34d22..d189be6cc6a1e410ab0928e03e0359e927082f25 100644 --- a/lib/gat/handlers/pool/pools/hybrid/factory.go +++ b/lib/gat/handlers/pool/pools/hybrid/factory.go @@ -1,6 +1,8 @@ package hybrid import ( + "fmt" + "github.com/caddyserver/caddy/v2" "gfx.cafe/gfx/pggat/lib/gat/handlers/pool" @@ -26,6 +28,19 @@ func (T *Factory) CaddyModule() caddy.ModuleInfo { func (T *Factory) Provision(ctx caddy.Context) error { T.Logger = ctx.Logger() + if T.RawCritics != nil { + raw, err := ctx.LoadModule(T, "RawCritics") + if err != nil { + return fmt.Errorf("loading critic module: %v", err) + } + + val := raw.([]any) + T.Critics = make([]pool.Critic, 0, len(val)) + for _, vv := range val { + T.Critics = append(T.Critics, vv.(pool.Critic)) + } + } + return nil } diff --git a/lib/gat/matchers/and.go b/lib/gat/matchers/and.go index e4106ed9846f357d87333f9688afd08735183e89..5f782d011a4920b3ed91e0c20d584cde03a5e567 100644 --- a/lib/gat/matchers/and.go +++ b/lib/gat/matchers/and.go @@ -32,12 +32,14 @@ func (T *And) CaddyModule() caddy.ModuleInfo { func (T *And) Provision(ctx caddy.Context) error { T.and = make([]gat.Matcher, 0, len(T.And)) if T.And != nil { - val, err := ctx.LoadModule(T, "And") + raw, err := ctx.LoadModule(T, "And") if err != nil { return fmt.Errorf("loading matcher module: %v", err) } - for _, vv := range val.([]any) { + val := raw.([]any) + T.and = make([]gat.Matcher, 0, len(val)) + for _, vv := range val { T.and = append(T.and, vv.(gat.Matcher)) } } diff --git a/lib/gat/matchers/or.go b/lib/gat/matchers/or.go index baf7e89f75d4669a52c2c924eb99ccac76f08059..2812c504c8dce2d58f199334c9a53033b723f712 100644 --- a/lib/gat/matchers/or.go +++ b/lib/gat/matchers/or.go @@ -32,12 +32,14 @@ func (T *Or) CaddyModule() caddy.ModuleInfo { func (T *Or) Provision(ctx caddy.Context) error { T.or = make([]gat.Matcher, 0, len(T.Or)) if T.Or != nil { - val, err := ctx.LoadModule(T, "Or") + raw, err := ctx.LoadModule(T, "Or") if err != nil { return fmt.Errorf("loading matcher module: %v", err) } - for _, vv := range val.([]any) { + val := raw.([]any) + T.or = make([]gat.Matcher, 0, len(val)) + for _, vv := range val { T.or = append(T.or, vv.(gat.Matcher)) } }