add reload and plugin support for hop
This commit is contained in:
@ -40,6 +40,47 @@ func KeyRedisLoaderOption(key string) RedisLoaderOption {
|
||||
}
|
||||
}
|
||||
|
||||
type redisStringLoader struct {
|
||||
client *redis.Client
|
||||
key string
|
||||
}
|
||||
|
||||
// RedisStringLoader loads data from redis string.
|
||||
func RedisStringLoader(addr string, opts ...RedisLoaderOption) Loader {
|
||||
var options redisLoaderOptions
|
||||
for _, opt := range opts {
|
||||
if opt != nil {
|
||||
opt(&options)
|
||||
}
|
||||
}
|
||||
|
||||
key := options.key
|
||||
if key == "" {
|
||||
key = DefaultRedisKey
|
||||
}
|
||||
|
||||
return &redisStringLoader{
|
||||
client: redis.NewClient(&redis.Options{
|
||||
Addr: addr,
|
||||
Password: options.password,
|
||||
DB: options.db,
|
||||
}),
|
||||
key: key,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *redisStringLoader) Load(ctx context.Context) (io.Reader, error) {
|
||||
v, err := p.client.Get(ctx, p.key).Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bytes.NewReader(v), nil
|
||||
}
|
||||
|
||||
func (p *redisStringLoader) Close() error {
|
||||
return p.client.Close()
|
||||
}
|
||||
|
||||
type redisSetLoader struct {
|
||||
client *redis.Client
|
||||
key string
|
||||
|
@ -2,6 +2,7 @@ package pht
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
@ -38,6 +39,7 @@ type serverOptions struct {
|
||||
tlsConfig *tls.Config
|
||||
readBufferSize int
|
||||
readTimeout time.Duration
|
||||
mptcp bool
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
@ -81,6 +83,12 @@ func ReadTimeoutServerOption(timeout time.Duration) ServerOption {
|
||||
}
|
||||
}
|
||||
|
||||
func MPTCPServerOption(mptcp bool) ServerOption {
|
||||
return func(opts *serverOptions) {
|
||||
opts.mptcp = mptcp
|
||||
}
|
||||
}
|
||||
|
||||
func LoggerServerOption(logger logger.Logger) ServerOption {
|
||||
return func(opts *serverOptions) {
|
||||
opts.logger = logger
|
||||
@ -187,7 +195,13 @@ func (s *Server) ListenAndServe() error {
|
||||
if xnet.IsIPv4(s.httpServer.Addr) {
|
||||
network = "tcp4"
|
||||
}
|
||||
ln, err := net.Listen(network, s.httpServer.Addr)
|
||||
|
||||
lc := net.ListenConfig{}
|
||||
if s.options.mptcp {
|
||||
lc.SetMultipathTCP(true)
|
||||
s.options.logger.Debugf("mptcp enabled: %v", lc.MultipathTCP())
|
||||
}
|
||||
ln, err := lc.Listen(context.Background(), network, s.httpServer.Addr)
|
||||
if err != nil {
|
||||
s.options.logger.Error(err)
|
||||
return err
|
||||
|
Reference in New Issue
Block a user