add skip for check exist method && handler for user methods

This commit is contained in:
DeniskaRediska committed 2020-01-17 13:21:23 +03:00
1 parent 08c4fb9bee
commit 91a14f9f23
14 files changed
+136 -87

No files matched your search

+6 -5
View File
@@ -26,29 +26,30 @@ type (
ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse
Consumer([]structure.AddressConfiguration) bool
SkipAuth() bool
SkipExistCheck() bool
Close()
}
)
func Init(protocol, pathPrefix string, skipAuth bool) (Proxy, error) {
func Init(protocol, pathPrefix string, skipAuth, skipExistCheck bool) (Proxy, error) {
if pathPrefix[0] != '/' {
return nil, errors.Errorf("path must begin with '/' in path '%s'", pathPrefix)
}
switch protocol {
case httpProtocol:
proxy := http.NewProxy(skipAuth)
proxy := http.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case grpcProtocol:
proxy := grpc.NewProxy(skipAuth)
proxy := grpc.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case healthCheckProtocol:
proxy := health_check.NewProxy(skipAuth)
proxy := health_check.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
case websocketProtocol:
proxy := websocket.NewProxy(skipAuth)
proxy := websocket.NewProxy(skipAuth, skipExistCheck)
store[pathPrefix] = proxy
return proxy, nil
default:
+10 -4
View File
@@ -16,11 +16,12 @@ import (
)
type grpcProxy struct {
client *backend.RxGrpcClient
skipAuth bool
client *backend.RxGrpcClient
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *grpcProxy {
func NewProxy(skipAuth, skipExistCheck bool) *grpcProxy {
return &grpcProxy{
client: backend.NewRxGrpcClient(
backend.WithDialOptions(
@@ -31,7 +32,8 @@ func NewProxy(skipAuth bool) *grpcProxy {
backend.WithDialingErrorHandler(func(err error) {
log.Errorf(log_code.ErrorClientGrpc, "dialing err: %v", err)
})),
skipAuth: skipAuth,
skipAuth: skipAuth,
skipExistCheck: skipExistCheck,
}
}
@@ -57,6 +59,10 @@ func (p *grpcProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *grpcProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *grpcProxy) Close() {
p.client.Close()
}
+8 -3
View File
@@ -7,11 +7,12 @@ import (
)
type healthCheckProxy struct {
skipAuth bool
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *healthCheckProxy {
return &healthCheckProxy{skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *healthCheckProxy {
return &healthCheckProxy{skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *healthCheckProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -28,6 +29,10 @@ func (p *healthCheckProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *healthCheckProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *healthCheckProxy) Close() {
}
+9 -4
View File
@@ -14,12 +14,13 @@ import (
)
type httpProxy struct {
client *fasthttp.HostClient
skipAuth bool
client *fasthttp.HostClient
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *httpProxy {
return &httpProxy{client: nil, skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *httpProxy {
return &httpProxy{client: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *httpProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -72,6 +73,10 @@ func (p *httpProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *httpProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
func (p *httpProxy) Close() {
p.client = nil
}
+9 -4
View File
@@ -41,12 +41,13 @@ var upgrader = websocket.FastHTTPUpgrader{
}
type websocketProxy struct {
addrs *RoundRobinAddrs
skipAuth bool
addrs *RoundRobinAddrs
skipAuth bool
skipExistCheck bool
}
func NewProxy(skipAuth bool) *websocketProxy {
return &websocketProxy{addrs: nil, skipAuth: skipAuth}
func NewProxy(skipAuth, skipExistCheck bool) *websocketProxy {
return &websocketProxy{addrs: nil, skipAuth: skipAuth, skipExistCheck: skipExistCheck}
}
func (p *websocketProxy) Consumer(addressList []structure.AddressConfiguration) bool {
@@ -129,6 +130,10 @@ func (p *websocketProxy) SkipAuth() bool {
return p.skipAuth
}
func (p *websocketProxy) SkipExistCheck() bool {
return p.skipExistCheck
}
// no-op
func (p *websocketProxy) Close() {
}