Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GitHub warnings #931

Merged
merged 15 commits into from
Feb 17, 2023
Prev Previous commit
Next Next commit
add RealIP to Request interface
  • Loading branch information
localvar committed Feb 6, 2023
commit 7cdca74c062dc5c8a4cbb0827eb7af6ac3a8a8d2
11 changes: 1 addition & 10 deletions pkg/filters/proxies/loadbalance.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,9 @@ func (lbp *WeightedRandomLoadBalancePolicy) ChooseServer(req protocols.Request,
type IPHashLoadBalancePolicy struct {
}

type realIPer interface {
RealIP() string
}

// ChooseServer chooses a server by ip hash.
func (lbp *IPHashLoadBalancePolicy) ChooseServer(req protocols.Request, sg *ServerGroup) *Server {
ri, ok := req.(realIPer)
if !ok {
panic("IPHashLoadBalancePolicy only support request with RealIP()")
}

ip := ri.RealIP()
ip := req.RealIP()
hash := fnv.New32()
hash.Write([]byte(ip))
return sg.Servers[hash.Sum32()%uint32(len(sg.Servers))]
Expand Down
7 changes: 1 addition & 6 deletions pkg/filters/proxies/requestmatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ type ipHashMatcher struct {

// Match implements protocols.Matcher.
func (iphm ipHashMatcher) Match(req protocols.Request) bool {
ri, ok := req.(realIPer)
if !ok {
panic("IPHashLoadBalancePolicy only support request with RealIP()")
}

ip := ri.RealIP()
ip := req.RealIP()
hash := fnv.New32()
hash.Write([]byte(ip))
return hash.Sum32()%1000 < iphm.permill
Expand Down
5 changes: 5 additions & 0 deletions pkg/protocols/mqttprot/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (r *Request) Header() protocols.Header {
return nil
}

// RealIP returns the real IP of the request.
func (r *Request) RealIP() string {
panic("not implemented")
}

// SetPayload set the payload of the request to payload.
func (r *Request) SetPayload(payload interface{}) {
p, ok := payload.([]byte)
Expand Down
3 changes: 3 additions & 0 deletions pkg/protocols/protocols.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type Request interface {
// Header returns the header of the request.
Header() Header

// RealIP returns the real IP of the request.
RealIP() string

// IsStream returns whether the payload is a stream, which cannot be
// read for more than once.
IsStream() bool
Expand Down