mirror of
https://github.com/eolinker/apinto
synced 2025-10-23 00:39:46 +08:00
优化灰度
This commit is contained in:
@@ -22,7 +22,7 @@ func (I *IPHandler) DoFilter(ctx eocontext.EoContext, next eocontext.IChain) (er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (I *IPHandler) doRestriction(ctx http_service.IHttpContext) error {
|
func (I *IPHandler) doRestriction(ctx http_service.IHttpContext) error {
|
||||||
realIP := ctx.Request().ReadIP()
|
realIP := ctx.Request().RealIp()
|
||||||
if I.filter != nil {
|
if I.filter != nil {
|
||||||
ok, err := I.filter(realIP)
|
ok, err := I.filter(realIP)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@@ -68,7 +68,7 @@ func (h *httpHandler) ServeHTTP(ctx eocontext.EoContext) {
|
|||||||
|
|
||||||
ctx.SetLabel("method", httpContext.Request().Method())
|
ctx.SetLabel("method", httpContext.Request().Method())
|
||||||
ctx.SetLabel("path", httpContext.Request().URI().RequestURI())
|
ctx.SetLabel("path", httpContext.Request().URI().RequestURI())
|
||||||
ctx.SetLabel("ip", httpContext.Request().ReadIP())
|
ctx.SetLabel("ip", httpContext.Request().RealIp())
|
||||||
|
|
||||||
ctx.SetCompleteHandler(h.completeHandler)
|
ctx.SetCompleteHandler(h.completeHandler)
|
||||||
ctx.SetApp(h.service)
|
ctx.SetApp(h.service)
|
||||||
|
@@ -53,6 +53,10 @@ type DubboContext struct {
|
|||||||
acceptTime time.Time
|
acceptTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *DubboContext) RealIP() string {
|
||||||
|
return d.netIP.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *DubboContext) Response() dubbo2_context.IResponse {
|
func (d *DubboContext) Response() dubbo2_context.IResponse {
|
||||||
|
|
||||||
return d.response
|
return d.response
|
||||||
|
@@ -59,6 +59,11 @@ type Context struct {
|
|||||||
errChan chan error
|
errChan chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) RealIP() string {
|
||||||
|
//TODO implement me
|
||||||
|
panic("implement me")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) EnableTls(b bool) {
|
func (c *Context) EnableTls(b bool) {
|
||||||
c.tls = b
|
c.tls = b
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,10 @@ type cloneContext struct {
|
|||||||
responseError error
|
responseError error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *cloneContext) RealIP() string {
|
||||||
|
return ctx.org.RealIP()
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *cloneContext) GetUpstreamHostHandler() eoscContext.UpstreamHostHandler {
|
func (ctx *cloneContext) GetUpstreamHostHandler() eoscContext.UpstreamHostHandler {
|
||||||
return ctx.upstreamHostHandler
|
return ctx.upstreamHostHandler
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,10 @@ type HttpContext struct {
|
|||||||
port int
|
port int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *HttpContext) RealIP() string {
|
||||||
|
return ctx.Request().RealIp()
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *HttpContext) GetUpstreamHostHandler() eoscContext.UpstreamHostHandler {
|
func (ctx *HttpContext) GetUpstreamHostHandler() eoscContext.UpstreamHostHandler {
|
||||||
return ctx.upstreamHostHandler
|
return ctx.upstreamHostHandler
|
||||||
}
|
}
|
||||||
|
@@ -49,7 +49,7 @@ func (r *RequestReader) URI() http_service.IURIReader {
|
|||||||
return &r.uri
|
return &r.uri
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RequestReader) ReadIP() string {
|
func (r *RequestReader) RealIp() string {
|
||||||
if r.realIP == "" {
|
if r.realIP == "" {
|
||||||
realIP := r.headers.GetHeader("x-real-ip")
|
realIP := r.headers.GetHeader("x-real-ip")
|
||||||
if realIP == "" {
|
if realIP == "" {
|
||||||
|
@@ -4,7 +4,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"github.com/eolinker/apinto/upstream/balance"
|
"github.com/eolinker/apinto/upstream/balance"
|
||||||
eoscContext "github.com/eolinker/eosc/eocontext"
|
eoscContext "github.com/eolinker/eosc/eocontext"
|
||||||
http_service "github.com/eolinker/eosc/eocontext/http-context"
|
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -43,12 +42,8 @@ func (r *ipHash) Select(ctx eoscContext.EoContext) (eoscContext.INode, int, erro
|
|||||||
|
|
||||||
// Next 由现有节点根据ip_hash决策出一个可用节点
|
// Next 由现有节点根据ip_hash决策出一个可用节点
|
||||||
func (r *ipHash) Next(org eoscContext.EoContext) (eoscContext.INode, int, error) {
|
func (r *ipHash) Next(org eoscContext.EoContext) (eoscContext.INode, int, error) {
|
||||||
httpContext, err := http_service.Assert(org)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
readIp := httpContext.Request().ReadIP()
|
readIp := org.RealIP()
|
||||||
nodes := org.GetApp().Nodes()
|
nodes := org.GetApp().Nodes()
|
||||||
size := len(nodes)
|
size := len(nodes)
|
||||||
if size < 1 {
|
if size < 1 {
|
||||||
|
Reference in New Issue
Block a user