William Petit
e66938f1d3
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
92 lines
1.9 KiB
Go
92 lines
1.9 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
)
|
|
|
|
type ProxyRepository interface {
|
|
CreateProxy(ctx context.Context, name ProxyName, to string, from ...string) (*Proxy, error)
|
|
UpdateProxy(ctx context.Context, name ProxyName, funcs ...UpdateProxyOptionFunc) (*Proxy, error)
|
|
QueryProxy(ctx context.Context, funcs ...QueryProxyOptionFunc) ([]*ProxyHeader, error)
|
|
GetProxy(ctx context.Context, name ProxyName) (*Proxy, error)
|
|
DeleteProxy(ctx context.Context, name ProxyName) error
|
|
}
|
|
|
|
type UpdateProxyOptionFunc func(*UpdateProxyOptions)
|
|
|
|
type UpdateProxyOptions struct {
|
|
To *string
|
|
From []string
|
|
Enabled *bool
|
|
Weight *int
|
|
}
|
|
|
|
func WithProxyUpdateEnabled(enabled bool) UpdateProxyOptionFunc {
|
|
return func(o *UpdateProxyOptions) {
|
|
o.Enabled = &enabled
|
|
}
|
|
}
|
|
|
|
func WithProxyUpdateWeight(weight int) UpdateProxyOptionFunc {
|
|
return func(o *UpdateProxyOptions) {
|
|
o.Weight = &weight
|
|
}
|
|
}
|
|
|
|
func WithProxyUpdateTo(to string) UpdateProxyOptionFunc {
|
|
return func(o *UpdateProxyOptions) {
|
|
o.To = &to
|
|
}
|
|
}
|
|
|
|
func WithProxyUpdateFrom(from ...string) UpdateProxyOptionFunc {
|
|
return func(o *UpdateProxyOptions) {
|
|
o.From = from
|
|
}
|
|
}
|
|
|
|
type QueryProxyOptionFunc func(*QueryProxyOptions)
|
|
|
|
type QueryProxyOptions struct {
|
|
To *url.URL
|
|
Names []ProxyName
|
|
Enabled *bool
|
|
From []string
|
|
}
|
|
|
|
func DefaultQueryProxyOptions() *QueryProxyOptions {
|
|
funcs := []QueryProxyOptionFunc{}
|
|
|
|
opts := &QueryProxyOptions{}
|
|
for _, fn := range funcs {
|
|
fn(opts)
|
|
}
|
|
|
|
return opts
|
|
}
|
|
|
|
func WithProxyQueryTo(to *url.URL) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.To = to
|
|
}
|
|
}
|
|
|
|
func WithProxyQueryFrom(from ...string) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.From = from
|
|
}
|
|
}
|
|
|
|
func WithProxyQueryNames(names ...ProxyName) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.Names = names
|
|
}
|
|
}
|
|
|
|
func WithProxyQueryEnabled(enabled bool) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.Enabled = &enabled
|
|
}
|
|
}
|