add plugin system

This commit is contained in:
ginuerzh
2023-04-18 20:52:56 +08:00
parent 7576651a67
commit 32c8188351
48 changed files with 761 additions and 115 deletions

View File

@ -12,6 +12,7 @@ import (
"github.com/go-gost/core/hosts"
"github.com/go-gost/core/logger"
"github.com/go-gost/x/internal/loader"
"google.golang.org/grpc"
)
type Mapping struct {
@ -24,6 +25,7 @@ type options struct {
fileLoader loader.Loader
redisLoader loader.Loader
httpLoader loader.Loader
client *grpc.ClientConn
period time.Duration
logger logger.Logger
}
@ -60,6 +62,12 @@ func HTTPLoaderOption(httpLoader loader.Loader) Option {
}
}
func PluginConnOption(c *grpc.ClientConn) Option {
return func(opts *options) {
opts.client = c
}
}
func LoggerOption(logger logger.Logger) Option {
return func(opts *options) {
opts.logger = logger
@ -104,7 +112,7 @@ func NewHostMapper(opts ...Option) hosts.HostMapper {
// Lookup searches the IP address corresponds to the given network and host from the host table.
// The network should be 'ip', 'ip4' or 'ip6', default network is 'ip'.
// the host should be a hostname (example.org) or a hostname with dot prefix (.example.org).
func (h *hostMapper) Lookup(network, host string) (ips []net.IP, ok bool) {
func (h *hostMapper) Lookup(ctx context.Context, network, host string) (ips []net.IP, ok bool) {
h.options.logger.Debugf("lookup %s/%s", host, network)
ips = h.lookup(host)
if ips == nil {