74 lines
1.6 KiB
Go
74 lines
1.6 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 {
|
|
To *url.URL
|
|
From []string
|
|
}
|
|
|
|
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
|
|
From []string
|
|
Offset *int
|
|
Limit *int
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|