update ingress interface
This commit is contained in:
parent
696d10fc28
commit
ca1f44d93c
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
||||
github.com/gin-contrib/cors v1.3.1
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-gost/core v0.0.0-20231109123312-8e4fc06cf1b7
|
||||
github.com/go-gost/core v0.0.0-20231113123850-a916f0401649
|
||||
github.com/go-gost/gosocks4 v0.0.1
|
||||
github.com/go-gost/gosocks5 v0.4.0
|
||||
github.com/go-gost/plugin v0.0.0-20231109123346-0ae4157b9d25
|
||||
|
2
go.sum
2
go.sum
@ -95,6 +95,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-gost/core v0.0.0-20231109123312-8e4fc06cf1b7 h1:sDsPtmP51qf8zN/RbZZj/3vNLCoH0sdvpIRwV6TfzvY=
|
||||
github.com/go-gost/core v0.0.0-20231109123312-8e4fc06cf1b7/go.mod h1:ndkgWVYRLwupVaFFWv8ML1Nr8tD3xhHK245PLpUDg4E=
|
||||
github.com/go-gost/core v0.0.0-20231113123850-a916f0401649 h1:14iGAk7cqc+aDWtsuY6CWpP0lvC54pA5Izjeh5FdQNs=
|
||||
github.com/go-gost/core v0.0.0-20231113123850-a916f0401649/go.mod h1:ndkgWVYRLwupVaFFWv8ML1Nr8tD3xhHK245PLpUDg4E=
|
||||
github.com/go-gost/gosocks4 v0.0.1 h1:+k1sec8HlELuQV7rWftIkmy8UijzUt2I6t+iMPlGB2s=
|
||||
github.com/go-gost/gosocks4 v0.0.1/go.mod h1:3B6L47HbU/qugDg4JnoFPHgJXE43Inz8Bah1QaN9qCc=
|
||||
github.com/go-gost/gosocks5 v0.4.0 h1:EIrOEkpJez4gwHrMa33frA+hHXJyevjp47thpMQsJzI=
|
||||
|
@ -259,8 +259,8 @@ func (ing *localIngress) Get(ctx context.Context, host string, opts ...ingress.G
|
||||
return ep
|
||||
}
|
||||
|
||||
func (ing *localIngress) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) {
|
||||
|
||||
func (ing *localIngress) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (ing *localIngress) lookup(host string) string {
|
||||
|
@ -62,15 +62,20 @@ func (p *grpcPlugin) Get(ctx context.Context, host string, opts ...ingress.GetOp
|
||||
return r.GetEndpoint()
|
||||
}
|
||||
|
||||
func (p *grpcPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) {
|
||||
func (p *grpcPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) bool {
|
||||
if p.client == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
p.client.Set(ctx, &proto.SetRequest{
|
||||
r, _ := p.client.Set(ctx, &proto.SetRequest{
|
||||
Host: host,
|
||||
Endpoint: endpoint,
|
||||
})
|
||||
if r == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return r.Ok
|
||||
}
|
||||
|
||||
func (p *grpcPlugin) Close() error {
|
||||
@ -94,6 +99,7 @@ type httpPluginSetRequest struct {
|
||||
}
|
||||
|
||||
type httpPluginSetResponse struct {
|
||||
OK bool `json:"ok"`
|
||||
}
|
||||
|
||||
type httpPlugin struct {
|
||||
@ -156,9 +162,9 @@ func (p *httpPlugin) Get(ctx context.Context, host string, opts ...ingress.GetOp
|
||||
return res.Endpoint
|
||||
}
|
||||
|
||||
func (p *httpPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) {
|
||||
func (p *httpPlugin) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) bool {
|
||||
if p.client == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
rb := httpPluginSetRequest{
|
||||
@ -167,12 +173,12 @@ func (p *httpPlugin) Set(ctx context.Context, host, endpoint string, opts ...ing
|
||||
}
|
||||
v, err := json.Marshal(&rb)
|
||||
if err != nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodPut, p.url, bytes.NewReader(v))
|
||||
if err != nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
if p.header != nil {
|
||||
@ -181,16 +187,17 @@ func (p *httpPlugin) Set(ctx context.Context, host, endpoint string, opts ...ing
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
resp, err := p.client.Do(req)
|
||||
if err != nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
res := httpPluginSetResponse{}
|
||||
res := httpPluginSetResponse{ }
|
||||
if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
return res.OK
|
||||
}
|
||||
|
@ -38,11 +38,11 @@ func (w *ingressWrapper) Get(ctx context.Context, host string, opts ...ingress.G
|
||||
return v.Get(ctx, host, opts...)
|
||||
}
|
||||
|
||||
func (w *ingressWrapper) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) {
|
||||
func (w *ingressWrapper) Set(ctx context.Context, host, endpoint string, opts ...ingress.SetOption) bool {
|
||||
v := w.r.get(w.name)
|
||||
if v == nil {
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
v.Set(ctx, host, endpoint, opts...)
|
||||
return v.Set(ctx, host, endpoint, opts...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user