mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-27 04:39:02 +03:00
Add ssm api server
This commit is contained in:
@@ -3,4 +3,5 @@ package option
|
||||
type ExperimentalOptions struct {
|
||||
ClashAPI *ClashAPIOptions `json:"clash_api,omitempty"`
|
||||
V2RayAPI *V2RayAPIOptions `json:"v2ray_api,omitempty"`
|
||||
SSMAPI *SSMAPIOptions `json:"ssm_api,omitempty"`
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ type ShadowsocksInboundOptions struct {
|
||||
Password string `json:"password"`
|
||||
Users []ShadowsocksUser `json:"users,omitempty"`
|
||||
Destinations []ShadowsocksDestination `json:"destinations,omitempty"`
|
||||
Managed bool `json:"managed,omitempty"`
|
||||
}
|
||||
|
||||
type ShadowsocksUser struct {
|
||||
|
||||
54
option/ssmapi.go
Normal file
54
option/ssmapi.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package option
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing-box/common/json"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
type SSMAPIOptions struct {
|
||||
Listen string `json:"listen,omitempty"`
|
||||
ListenPrefix string `json:"listen_prefix,omitempty"`
|
||||
Nodes []SSMNode `json:"nodes,omitempty"`
|
||||
}
|
||||
|
||||
type _SSMNode struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
ShadowsocksOptions SSMShadowsocksNode `json:"-"`
|
||||
}
|
||||
|
||||
type SSMNode _SSMNode
|
||||
|
||||
func (h SSMNode) MarshalJSON() ([]byte, error) {
|
||||
var v any
|
||||
switch h.Type {
|
||||
case C.TypeShadowsocks:
|
||||
v = h.ShadowsocksOptions
|
||||
default:
|
||||
return nil, E.New("unknown ssm node type: ", h.Type)
|
||||
}
|
||||
return MarshallObjects((_SSMNode)(h), v)
|
||||
}
|
||||
|
||||
func (h *SSMNode) UnmarshalJSON(data []byte) error {
|
||||
err := json.Unmarshal(data, (*_SSMNode)(h))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var v any
|
||||
switch h.Type {
|
||||
case C.TypeShadowsocks:
|
||||
v = &h.ShadowsocksOptions
|
||||
default:
|
||||
return E.New("unknown ssm node type: ", h.Type)
|
||||
}
|
||||
return UnmarshallExcluded(data, (*_SSMNode)(h), v)
|
||||
}
|
||||
|
||||
type SSMShadowsocksNode struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Address string `json:"address"`
|
||||
Tags []string `json:"tags"`
|
||||
Inbound string `json:"inbound"`
|
||||
}
|
||||
Reference in New Issue
Block a user