111 lines
2.3 KiB
Go
111 lines
2.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
)
|
|
|
|
type ProxyRepository interface {
|
|
CreateProxy(ctx context.Context, name ProxyName, to *url.URL, 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 {
|
|
Offset *int
|
|
Limit *int
|
|
To *url.URL
|
|
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 *url.URL) 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
|
|
Offset *int
|
|
Limit *int
|
|
}
|
|
|
|
func DefaultQueryProxyOptions() *QueryProxyOptions {
|
|
funcs := []QueryProxyOptionFunc{
|
|
WithProxyQueryOffset(0),
|
|
WithProxyQueryLimit(0),
|
|
}
|
|
|
|
opts := &QueryProxyOptions{}
|
|
for _, fn := range funcs {
|
|
fn(opts)
|
|
}
|
|
|
|
return opts
|
|
}
|
|
|
|
func WithProxyQueryOffset(offset int) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.Offset = &offset
|
|
}
|
|
}
|
|
|
|
func WithProxyQueryLimit(limit int) QueryProxyOptionFunc {
|
|
return func(o *QueryProxyOptions) {
|
|
o.Limit = &limit
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|