实现手动 proxy 同步接口
This commit is contained in:
@@ -19,7 +19,11 @@ func IsGostNotFound(err error) bool {
|
||||
}
|
||||
|
||||
type GostClient interface {
|
||||
ListChains() ([]*GostChainConfig, error)
|
||||
GetChain(name string) (*GostChainConfig, error)
|
||||
CreateChain(chain *GostChainConfig) error
|
||||
DeleteChain(name string) error
|
||||
SaveConfig() error
|
||||
CreateService(service *GostServiceConfig) error
|
||||
DeleteService(name string) error
|
||||
CreateAuther(auther *GostAutherConfig) error
|
||||
@@ -54,15 +58,37 @@ func NewGost(host string, port int, pathPrefix, username, password string) GostC
|
||||
}
|
||||
|
||||
type GostChainConfig struct {
|
||||
Name string `json:"name"`
|
||||
Name string `json:"name"`
|
||||
Hops []GostHopConfig `json:"hops,omitempty"`
|
||||
}
|
||||
|
||||
type GostHopConfig struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Nodes []GostNodeConfig `json:"nodes,omitempty"`
|
||||
}
|
||||
|
||||
type GostNodeConfig struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Addr string `json:"addr"`
|
||||
Connector GostConnectorConfig `json:"connector"`
|
||||
Dialer GostDialerConfig `json:"dialer"`
|
||||
}
|
||||
|
||||
type GostConnectorConfig struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GostDialerConfig struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GostServiceConfig struct {
|
||||
Name string `json:"name"`
|
||||
Addr string `json:"addr"`
|
||||
Admission string `json:"admission,omitempty"`
|
||||
Handler GostHandlerConfig `json:"handler"`
|
||||
Listener GostListenerConfig `json:"listener"`
|
||||
Name string `json:"name"`
|
||||
Addr string `json:"addr"`
|
||||
Admission string `json:"admission,omitempty"`
|
||||
Handler GostHandlerConfig `json:"handler"`
|
||||
Listener GostListenerConfig `json:"listener"`
|
||||
Recorders []GostRecorderConfig `json:"recorders,omitempty"`
|
||||
}
|
||||
|
||||
type GostHandlerConfig struct {
|
||||
@@ -75,6 +101,11 @@ type GostListenerConfig struct {
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type GostRecorderConfig struct {
|
||||
Name string `json:"name"`
|
||||
Record string `json:"record"`
|
||||
}
|
||||
|
||||
type GostAutherConfig struct {
|
||||
Name string `json:"name"`
|
||||
Auths []GostAuthConfig `json:"auths"`
|
||||
@@ -115,6 +146,40 @@ func (c *gostClient) GetChain(name string) (*GostChainConfig, error) {
|
||||
return &GostChainConfig{Name: name}, nil
|
||||
}
|
||||
|
||||
func (c *gostClient) ListChains() ([]*GostChainConfig, error) {
|
||||
body, err := c.get("/config/chains")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(body) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
Data struct {
|
||||
Count int `json:"count"`
|
||||
List []*GostChainConfig `json:"list"`
|
||||
} `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &resp); err != nil {
|
||||
return nil, fmt.Errorf("parse gost chain list failed %s: %w", string(body), err)
|
||||
}
|
||||
|
||||
return resp.Data.List, nil
|
||||
}
|
||||
|
||||
func (c *gostClient) CreateChain(chain *GostChainConfig) error {
|
||||
return c.create("/config/chains", chain)
|
||||
}
|
||||
|
||||
func (c *gostClient) DeleteChain(name string) error {
|
||||
return c.delete("/config/chains/" + url.PathEscape(name))
|
||||
}
|
||||
|
||||
func (c *gostClient) SaveConfig() error {
|
||||
return c.create("/config", nil)
|
||||
}
|
||||
|
||||
func (c *gostClient) CreateService(service *GostServiceConfig) error {
|
||||
return c.create("/config/services", service)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user