add router interface

This commit is contained in:
ginuerzh 2023-11-19 14:20:35 +08:00
parent 486f2cee61
commit 6b01698ea9
2 changed files with 36 additions and 7 deletions

View File

@ -2,15 +2,20 @@ package ingress
import "context"
type GetOptions struct{}
type Options struct{}
type GetOption func(opts *GetOptions)
type Option func(opts *Options)
type SetOptions struct{}
type SetOption func(opts *SetOptions)
type Rule struct {
// Hostname is the hostname match pattern, e.g. example.com, *.example.org or .example.com.
Hostname string
// Endpoint is the tunnel ID for the hostname.
Endpoint string
}
type Ingress interface {
Get(ctx context.Context, host string, opts ...GetOption) string
Set(ctx context.Context, host, endpoint string, opts ...SetOption) bool
// SetRule adds or updates a rule for the ingress.
SetRule(ctx context.Context, rule *Rule, opts ...Option) bool
// GetRule queries a rule by host.
GetRule(ctx context.Context, host string, opts ...Option) *Rule
}

24
router/router.go Normal file
View File

@ -0,0 +1,24 @@
package router
import (
"context"
"net"
)
type Options struct{}
type Option func(opts *Options)
type Route struct {
// Net is the destination network, e.g. 192.168.0.0/16, 172.10.10.0/24.
Net *net.IPNet
// Gateway is the gateway for the destination network.
Gateway net.IP
}
type Router interface {
// SetRoute adds or updates a route for the router.
SetRoute(ctx context.Context, route *Route, opts ...Option) bool
// GetRoute queries a route by destination IP address.
GetRoute(ctx context.Context, dst net.IP, opts ...Option) *Route
}