feat: initial commit
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
91
internal/store/proxy_repository.go
Normal file
91
internal/store/proxy_repository.go
Normal file
@ -0,0 +1,91 @@
|
||||
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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user