├── .gitignore ├── go.mod ├── pkg ├── response.go ├── enum.go ├── id.go ├── method.go ├── util.go ├── util_test.go └── softether_jsonrpc.go ├── methods ├── create_user_test.go ├── test_method_test.go ├── test_method.go ├── enum_hub.go ├── enum_listener.go ├── enum_user.go ├── get_server_info.go ├── get_server_status.go ├── enum_connection.go ├── get_hub_status.go ├── get_user.go ├── get_hub.go ├── enum_ethernet.go ├── enum_NAT.go ├── enum_link.go ├── get_connection_info.go ├── delete_hub.go ├── enum_DHCP.go ├── set_server_password.go ├── enum_local_bridge.go ├── get_bridge_support.go ├── disconnect_connection.go ├── set_hub_online.go ├── delete_listener.go ├── set_link_online.go ├── get_link_status.go ├── add_local_bridge.go ├── set_link_offline.go ├── enable_secure_NAT.go ├── disable_secure_NAT.go ├── get_link.go ├── delete_link.go ├── delete_local_bridge.go ├── create_listener.go ├── enable_listener.go ├── get_secure_NAT_status.go ├── get_secure_NAT_option.go ├── rename_link.go ├── set_hub.go ├── create_hub.go ├── set_secure_NAT_option.go ├── set_link.go ├── create_link.go ├── create_user.go └── set_user.go ├── LICENSE ├── README.md └── api.go /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | api_test.go -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/terassyi/go-softether-api 2 | 3 | go 1.13 4 | -------------------------------------------------------------------------------- /pkg/response.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | type Response interface { 4 | Id() int 5 | Result() (map[string]interface{}, error) 6 | } 7 | -------------------------------------------------------------------------------- /pkg/enum.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | const ( 4 | str = "_str" 5 | utf = "_utf" 6 | bin = "_bin" 7 | ip = "_ip" 8 | u32 = "_u32" 9 | u64 = "_u64" 10 | boolean = "_bool" 11 | date = "_dt" 12 | ) 13 | -------------------------------------------------------------------------------- /methods/create_user_test.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestCreateUserParams_Tags(t *testing.T) { 9 | m := NewCreateUser("test", "test_user", "hoge", "test", nil, 1) 10 | tags := m.Params.Tags() 11 | fmt.Println(tags) 12 | } 13 | -------------------------------------------------------------------------------- /pkg/id.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | // Id interface is used for request id 4 | type Id interface { 5 | Incl() 6 | Describe() int 7 | } 8 | 9 | // id struct is the implement of Id interface 10 | type id int 11 | 12 | // This method increment an id 13 | func (i *id) Incl() { 14 | *i += 1 15 | } 16 | 17 | func (i *id) Describe() int { 18 | return int(*i) 19 | } 20 | -------------------------------------------------------------------------------- /methods/test_method_test.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import "testing" 4 | 5 | func TestTest_Name(t *testing.T) { 6 | p := NewTest() 7 | if p.Name() != "Test" { 8 | t.Fatalf("actual: %v", p.Name()) 9 | } 10 | } 11 | 12 | func TestTest_Marshall(t *testing.T) { 13 | r := NewTest() 14 | b, err := r.Marshall() 15 | if err != nil { 16 | t.Fatal(err) 17 | } 18 | wanted := "{\"jsonrpc\":\"2.0\",\"id\":0,\"method\":\"Test\",\"params\":{\"IntValue_u32\":0}}" 19 | if string(b) != wanted { 20 | t.Fatalf("actual: %v", string(b)) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /pkg/method.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | // Method interface is type for API request 4 | type Method interface { 5 | Name() string 6 | GetId() int 7 | SetId(id int) 8 | Parameter() Params 9 | Marshall() ([]byte, error) 10 | } 11 | 12 | type Params interface { 13 | Tags() []string 14 | } 15 | 16 | const ( 17 | ver = "2.0" 18 | ) 19 | 20 | type Base struct { 21 | Jsonrpc string `json:"jsonrpc"` 22 | Id int `json:"id"` 23 | Name string `json:"method"` 24 | } 25 | 26 | func NewBase(name string) Base { 27 | return Base{ 28 | Jsonrpc: ver, 29 | Id: 0, 30 | Name: name, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /methods/test_method.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type Test struct { 9 | pkg.Base 10 | Params *TestParams `json:"params"` 11 | } 12 | 13 | func NewTest() *Test { 14 | return &Test{ 15 | Base: pkg.NewBase("Test"), 16 | Params: &TestParams{IntValue: 0}, 17 | } 18 | } 19 | 20 | func (m *Test) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *Test) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *Test) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *Test) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *Test) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type TestParams struct { 41 | IntValue int `json:"IntValue_u32"` 42 | } 43 | 44 | func (p *TestParams) Tags() []string { 45 | return []string{"IntValue_u32"} 46 | } 47 | -------------------------------------------------------------------------------- /methods/enum_hub.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type EnumHub struct { 10 | pkg.Base 11 | Params *EnumHubParams `json:"params"` 12 | } 13 | 14 | func (g *EnumHub) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewEnumHub() *EnumHub { 19 | return &EnumHub{ 20 | Base: pkg.NewBase("EnumHub"), 21 | Params: &EnumHubParams{}, 22 | } 23 | } 24 | 25 | func (g *EnumHub) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *EnumHub) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *EnumHub) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *EnumHub) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type EnumHubParams struct{} 47 | 48 | func (p *EnumHubParams) Tags() []string { 49 | return []string{} 50 | } 51 | -------------------------------------------------------------------------------- /methods/enum_listener.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type EnumListener struct { 10 | pkg.Base 11 | Params *EnumListenerParams `json:"params"` 12 | } 13 | 14 | func (g *EnumListener) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewEnumListener() *EnumListener { 19 | return &EnumListener{ 20 | Base: pkg.NewBase("EnumListener"), 21 | Params: nil, 22 | } 23 | } 24 | 25 | func (g *EnumListener) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *EnumListener) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *EnumListener) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *EnumListener) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type EnumListenerParams struct{} 47 | 48 | func (p *EnumListenerParams) Tags() []string { 49 | return []string{} 50 | } 51 | -------------------------------------------------------------------------------- /methods/enum_user.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type EnumUser struct { 9 | pkg.Base 10 | Params *EnumUserParams `json:"params"` 11 | } 12 | 13 | func (g *EnumUser) Parameter() pkg.Params { 14 | return g.Params 15 | } 16 | 17 | func NewEnumUser(hub string) *EnumUser { 18 | return &EnumUser{ 19 | Base: pkg.NewBase("EnumUser"), 20 | Params: newEnumUserParams(hub), 21 | } 22 | } 23 | 24 | func (g *EnumUser) Name() string { 25 | return g.Base.Name 26 | } 27 | 28 | func (g *EnumUser) GetId() int { 29 | return g.Id 30 | } 31 | 32 | func (g *EnumUser) SetId(id int) { 33 | g.Base.Id = id 34 | } 35 | 36 | func (g *EnumUser) Marshall() ([]byte, error) { 37 | return json.Marshal(g) 38 | } 39 | 40 | type EnumUserParams struct { 41 | HubName string `json:"HubName_str"` 42 | } 43 | 44 | func newEnumUserParams(hub string) *EnumUserParams { 45 | return &EnumUserParams{ 46 | HubName: hub, 47 | } 48 | } 49 | 50 | func (p *EnumUserParams) Tags() []string { 51 | return []string{"HubName_str"} 52 | } 53 | -------------------------------------------------------------------------------- /methods/get_server_info.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type GetServerInfo struct { 10 | pkg.Base 11 | Params *GetServerInfoParams `json:"params"` 12 | } 13 | 14 | func (g *GetServerInfo) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewGetServerInfo() *GetServerInfo { 19 | return &GetServerInfo{ 20 | Base: pkg.NewBase("GetServerInfo"), 21 | Params: nil, 22 | } 23 | } 24 | 25 | func (g *GetServerInfo) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *GetServerInfo) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *GetServerInfo) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *GetServerInfo) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type GetServerInfoParams struct{} 47 | 48 | func (p *GetServerInfoParams) Tags() []string { 49 | return []string{} 50 | } 51 | -------------------------------------------------------------------------------- /methods/get_server_status.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type GetServerStatus struct { 10 | pkg.Base 11 | Params *GetServerStatusParams `json:"params"` 12 | } 13 | 14 | func (g *GetServerStatus) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewGetServerStatus() *GetServerStatus { 19 | return &GetServerStatus{ 20 | Base: pkg.NewBase("GetServerStatus"), 21 | Params: nil, 22 | } 23 | } 24 | 25 | func (g *GetServerStatus) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *GetServerStatus) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *GetServerStatus) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *GetServerStatus) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type GetServerStatusParams struct{} 47 | 48 | func (p *GetServerStatusParams) Tags() []string { 49 | return []string{} 50 | } 51 | -------------------------------------------------------------------------------- /methods/enum_connection.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type EnumConnection struct { 10 | pkg.Base 11 | Params *EnumConnectionParams `json:"params"` 12 | } 13 | 14 | func (g *EnumConnection) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewEnumConnection() *EnumConnection { 19 | return &EnumConnection{ 20 | Base: pkg.NewBase("EnumConnection"), 21 | Params: &EnumConnectionParams{}, 22 | } 23 | } 24 | 25 | func (g *EnumConnection) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *EnumConnection) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *EnumConnection) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *EnumConnection) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type EnumConnectionParams struct{} 47 | 48 | func (p *EnumConnectionParams) Tags() []string { 49 | return []string{} 50 | } 51 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 terassyi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /methods/get_hub_status.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type GetHubStatus struct { 9 | pkg.Base 10 | Params *GetHubStatusParams `json:"params"` 11 | } 12 | 13 | func NewGetHubStatus(name string) *GetHubStatus { 14 | return &GetHubStatus{ 15 | Base: pkg.NewBase("GetHubStatus"), 16 | Params: newGetHubStatusParams(name), 17 | } 18 | } 19 | 20 | func (m *GetHubStatus) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *GetHubStatus) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *GetHubStatus) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *GetHubStatus) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *GetHubStatus) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type GetHubStatusParams struct { 41 | Name string `json:"Name_str"` 42 | } 43 | 44 | func newGetHubStatusParams(name string) *GetHubStatusParams { 45 | return &GetHubStatusParams{ 46 | Name: name, 47 | } 48 | } 49 | 50 | func (p *GetHubStatusParams) Tags() []string { 51 | return []string{ 52 | "Name_str", 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /methods/get_user.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type GetUser struct { 9 | pkg.Base 10 | Params *GetUserParams `json:"params"` 11 | } 12 | 13 | func (m *GetUser) Parameter() pkg.Params { 14 | return m.Params 15 | } 16 | 17 | func NewGetUser(hub, name string) *GetUser { 18 | return &GetUser{ 19 | Base: pkg.NewBase("GetUser"), 20 | Params: newGetUserParams(hub, name), 21 | } 22 | } 23 | 24 | func (m *GetUser) Name() string { 25 | return m.Base.Name 26 | } 27 | 28 | func (m *GetUser) GetId() int { 29 | return m.Id 30 | } 31 | 32 | func (m *GetUser) SetId(id int) { 33 | m.Base.Id = id 34 | } 35 | 36 | func (m *GetUser) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type GetUserParams struct { 41 | HubName string `json:"HubName_str"` 42 | Name string `json:"Name_str"` 43 | } 44 | 45 | func newGetUserParams(hub, name string) *GetUserParams { 46 | return &GetUserParams{ 47 | HubName: hub, 48 | Name: name, 49 | } 50 | } 51 | 52 | func (p *GetUserParams) Tags() []string { 53 | return []string{ 54 | "HubName_str", 55 | "Name_str", 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /methods/get_hub.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type GetHub struct { 10 | pkg.Base 11 | Params *GetHubParams `json:"params"` 12 | } 13 | 14 | func NewGetHub(name string) *GetHub { 15 | return &GetHub{ 16 | Base: pkg.NewBase("GetHub"), 17 | Params: newGetHubParams(name), 18 | } 19 | } 20 | 21 | func (m *GetHub) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *GetHub) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *GetHub) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *GetHub) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *GetHub) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(m) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type GetHubParams struct { 47 | HubName string `json:"HubName_str"` 48 | } 49 | 50 | func newGetHubParams(name string) *GetHubParams { 51 | return &GetHubParams{HubName: name} 52 | } 53 | 54 | func (p *GetHubParams) Tags() []string { 55 | return []string{ 56 | "HubName_str", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/enum_ethernet.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnumEthernet struct { 11 | pkg.Base 12 | Params *EnumEthernetParams `json:"params"` 13 | } 14 | 15 | func (g *EnumEthernet) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnumEthernet() *EnumEthernet { 20 | return &EnumEthernet{ 21 | Base: pkg.NewBase("EnumEthernet"), 22 | Params: newEnumEthernetParams(), 23 | } 24 | } 25 | 26 | func (g *EnumEthernet) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnumEthernet) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnumEthernet) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnumEthernet) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnumEthernetParams struct { 48 | } 49 | 50 | func newEnumEthernetParams() *EnumEthernetParams { 51 | return &EnumEthernetParams{} 52 | } 53 | 54 | func (p *EnumEthernetParams) Tags() []string { 55 | return []string{} 56 | } 57 | -------------------------------------------------------------------------------- /methods/enum_NAT.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnumNAT struct { 11 | pkg.Base 12 | Params *EnumNATParams `json:"params"` 13 | } 14 | 15 | func (g *EnumNAT) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnumNAT(hubName string) *EnumNAT { 20 | return &EnumNAT{ 21 | Base: pkg.NewBase("EnumNAT"), 22 | Params: newEnumNATParams(hubName), 23 | } 24 | } 25 | 26 | func (g *EnumNAT) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnumNAT) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnumNAT) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnumNAT) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnumNATParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newEnumNATParams(hubName string) *EnumNATParams { 52 | return &EnumNATParams{ 53 | HubName: hubName, 54 | } 55 | } 56 | 57 | func (p *EnumNATParams) Tags() []string { 58 | return []string{"HubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/enum_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnumLink struct { 11 | pkg.Base 12 | Params *EnumLinkParams `json:"params"` 13 | } 14 | 15 | func (g *EnumLink) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnumLink(name string) *EnumLink { 20 | return &EnumLink{ 21 | Base: pkg.NewBase("EnumLink"), 22 | Params: newEnumLinkParams(name), 23 | } 24 | } 25 | 26 | func (g *EnumLink) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnumLink) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnumLink) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnumLink) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnumLinkParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newEnumLinkParams(name string) *EnumLinkParams { 52 | return &EnumLinkParams{HubName: name} 53 | } 54 | 55 | func (p *EnumLinkParams) Tags() []string { 56 | return []string{ 57 | "HubName_str", 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /methods/get_connection_info.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type GetConnectionInfo struct { 9 | pkg.Base 10 | Params *GetConnectionInfoParams `json:"params"` 11 | } 12 | 13 | func NewGetConnectionInfo(name string) *GetConnectionInfo { 14 | return &GetConnectionInfo{ 15 | Base: pkg.NewBase("GetConnectionInfo"), 16 | Params: newGetConnectionInfoParams(name), 17 | } 18 | } 19 | 20 | func (m *GetConnectionInfo) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *GetConnectionInfo) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *GetConnectionInfo) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *GetConnectionInfo) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *GetConnectionInfo) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type GetConnectionInfoParams struct { 41 | Name string `json:"Name_str"` 42 | } 43 | 44 | func newGetConnectionInfoParams(name string) *GetConnectionInfoParams { 45 | return &GetConnectionInfoParams{ 46 | Name: name, 47 | } 48 | } 49 | 50 | func (p *GetConnectionInfoParams) Tags() []string { 51 | return []string{ 52 | "Name_str", 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /methods/delete_hub.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type DeleteHub struct { 10 | pkg.Base 11 | Params *DeleteHubParams `json:"params"` 12 | } 13 | 14 | func NewDeleteHub(name string) *DeleteHub { 15 | return &DeleteHub{ 16 | Base: pkg.NewBase("DeleteHub"), 17 | Params: newDeleteHubParams(name), 18 | } 19 | } 20 | func (m *DeleteHub) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *DeleteHub) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *DeleteHub) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *DeleteHub) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *DeleteHub) Marshall() ([]byte, error) { 37 | data, err := json.Marshal(m) 38 | if err != nil { 39 | return nil, err 40 | } 41 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 42 | return res, nil 43 | } 44 | 45 | type DeleteHubParams struct { 46 | HubName string `json:"HubName_str"` 47 | } 48 | 49 | func newDeleteHubParams(hub string) *DeleteHubParams { 50 | return &DeleteHubParams{HubName: hub} 51 | } 52 | 53 | func (p *DeleteHubParams) Tags() []string { 54 | return []string{ 55 | "HubName_str", 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /methods/enum_DHCP.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnumDHCP struct { 11 | pkg.Base 12 | Params *EnumDHCPParams `json:"params"` 13 | } 14 | 15 | func (g *EnumDHCP) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnumDHCP(hubName string) *EnumDHCP { 20 | return &EnumDHCP{ 21 | Base: pkg.NewBase("EnumDHCP"), 22 | Params: newEnumDHCPParams(hubName), 23 | } 24 | } 25 | 26 | func (g *EnumDHCP) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnumDHCP) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnumDHCP) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnumDHCP) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnumDHCPParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newEnumDHCPParams(hubName string) *EnumDHCPParams { 52 | return &EnumDHCPParams{ 53 | HubName: hubName, 54 | } 55 | } 56 | 57 | func (p *EnumDHCPParams) Tags() []string { 58 | return []string{"HubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/set_server_password.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type SetServerPassword struct { 9 | pkg.Base 10 | Params *SetServerPasswordParams `json:"params"` 11 | } 12 | 13 | func NewSetServerPassword() *SetServerPassword { 14 | return &SetServerPassword{ 15 | Base: pkg.NewBase("SetServerPassword"), 16 | Params: newSetServerPasswordParams("test"), 17 | } 18 | } 19 | 20 | func (m *SetServerPassword) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *SetServerPassword) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *SetServerPassword) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *SetServerPassword) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *SetServerPassword) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type SetServerPasswordParams struct { 41 | PlainTextPassword string `json:"PlainTextPassword_str"` 42 | } 43 | 44 | func newSetServerPasswordParams(text string) *SetServerPasswordParams { 45 | return &SetServerPasswordParams{PlainTextPassword: text} 46 | } 47 | 48 | func (p *SetServerPasswordParams) Tags() []string { 49 | return []string{"PlainTextPassword_str"} 50 | } 51 | -------------------------------------------------------------------------------- /methods/enum_local_bridge.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnumLocalBridge struct { 11 | pkg.Base 12 | Params *EnumLocalBridgeParams `json:"params"` 13 | } 14 | 15 | func (g *EnumLocalBridge) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnumLocalBridge() *EnumLocalBridge { 20 | return &EnumLocalBridge{ 21 | Base: pkg.NewBase("EnumLocalBridge"), 22 | Params: newEnumLocalBridgeParams(), 23 | } 24 | } 25 | 26 | func (g *EnumLocalBridge) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnumLocalBridge) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnumLocalBridge) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnumLocalBridge) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnumLocalBridgeParams struct { 48 | } 49 | 50 | func newEnumLocalBridgeParams() *EnumLocalBridgeParams { 51 | return &EnumLocalBridgeParams{} 52 | } 53 | 54 | func (p *EnumLocalBridgeParams) Tags() []string { 55 | return []string{} 56 | } 57 | -------------------------------------------------------------------------------- /methods/get_bridge_support.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type GetBridgeSupport struct { 11 | pkg.Base 12 | Params *GetBridgeSupportParams `json:"params"` 13 | } 14 | 15 | func (g *GetBridgeSupport) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewGetBridgeSupport() *GetBridgeSupport { 20 | return &GetBridgeSupport{ 21 | Base: pkg.NewBase("GetBridgeSupport"), 22 | Params: newGetBridgeSupportParams(), 23 | } 24 | } 25 | 26 | func (g *GetBridgeSupport) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *GetBridgeSupport) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *GetBridgeSupport) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *GetBridgeSupport) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type GetBridgeSupportParams struct { 48 | } 49 | 50 | func newGetBridgeSupportParams() *GetBridgeSupportParams { 51 | return &GetBridgeSupportParams{} 52 | } 53 | 54 | func (p *GetBridgeSupportParams) Tags() []string { 55 | return []string{} 56 | } 57 | -------------------------------------------------------------------------------- /methods/disconnect_connection.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type DisconnectConnection struct { 9 | pkg.Base 10 | Params *DisconnectConnectionParams `json:"params"` 11 | } 12 | 13 | func NewDisconnectConnection(name string) *DisconnectConnection { 14 | return &DisconnectConnection{ 15 | Base: pkg.NewBase("DisconnectConnection"), 16 | Params: newDisconnectConnectionParams(name), 17 | } 18 | } 19 | 20 | func (m *DisconnectConnection) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *DisconnectConnection) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *DisconnectConnection) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *DisconnectConnection) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *DisconnectConnection) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type DisconnectConnectionParams struct { 41 | Name string `json:"Name_str"` 42 | } 43 | 44 | func newDisconnectConnectionParams(name string) *DisconnectConnectionParams { 45 | return &DisconnectConnectionParams{ 46 | Name: name, 47 | } 48 | } 49 | 50 | func (p *DisconnectConnectionParams) Tags() []string { 51 | return []string{ 52 | "Name_str", 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /methods/set_hub_online.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type SetHubOnline struct { 10 | pkg.Base 11 | Params *SetHubOnlineParams `json:"params"` 12 | } 13 | 14 | func NewSetHubOnline(name string, online bool) *SetHubOnline { 15 | return &SetHubOnline{ 16 | Base: pkg.NewBase("SetHubOnline"), 17 | Params: newSetHubOnlineParams(name, online), 18 | } 19 | } 20 | 21 | func (m *SetHubOnline) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *SetHubOnline) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *SetHubOnline) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *SetHubOnline) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *SetHubOnline) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type SetHubOnlineParams struct { 42 | HubName string `json:"HubName_str"` 43 | Online bool `json:"Online_bool"` 44 | } 45 | 46 | func newSetHubOnlineParams(name string, online bool) *SetHubOnlineParams { 47 | return &SetHubOnlineParams{ 48 | HubName: name, 49 | Online: online, 50 | } 51 | } 52 | 53 | func (p *SetHubOnlineParams) Tags() []string { 54 | return []string{ 55 | "HubName_str", 56 | "Online_bool", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/delete_listener.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type DeleteListener struct { 10 | pkg.Base 11 | Params *DeleteListenerParams `json:"params"` 12 | } 13 | 14 | func (g *DeleteListener) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewDeleteListener(port int) *DeleteListener { 19 | return &DeleteListener{ 20 | Base: pkg.NewBase("DeleteListener"), 21 | Params: newDeleteListenerParams(port), 22 | } 23 | } 24 | 25 | func (g *DeleteListener) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *DeleteListener) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *DeleteListener) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *DeleteListener) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type DeleteListenerParams struct { 47 | Port int `json:"Port_u32"` 48 | } 49 | 50 | func newDeleteListenerParams(port int) *DeleteListenerParams { 51 | return &DeleteListenerParams{Port: port} 52 | } 53 | 54 | func (p *DeleteListenerParams) Tags() []string { 55 | return []string{"Port_u32"} 56 | } 57 | -------------------------------------------------------------------------------- /methods/set_link_online.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type SetLinkOnline struct { 10 | pkg.Base 11 | Params *SetLinkOnlineParams `json:"params"` 12 | } 13 | 14 | func NewSetLinkOnline(hubname, accountname string) *SetLinkOnline { 15 | return &SetLinkOnline{ 16 | Base: pkg.NewBase("SetLinkOnline"), 17 | Params: newSetLinkOnlineParams(hubname, accountname), 18 | } 19 | } 20 | 21 | func (m *SetLinkOnline) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *SetLinkOnline) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *SetLinkOnline) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *SetLinkOnline) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *SetLinkOnline) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type SetLinkOnlineParams struct { 42 | HubName string `json:"HubName_str"` 43 | AccountName string `json:"AccountName_utf"` 44 | } 45 | 46 | func newSetLinkOnlineParams(hubname, accountname string) *SetLinkOnlineParams { 47 | return &SetLinkOnlineParams{ 48 | HubName: hubname, 49 | AccountName: accountname, 50 | } 51 | } 52 | 53 | func (p *SetLinkOnlineParams) Tags() []string { 54 | return []string{ 55 | "HubName_str", 56 | "AccountName_utf", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/get_link_status.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type GetLinkStatus struct { 10 | pkg.Base 11 | Params *GetLinkStatusParams `json:"params"` 12 | } 13 | 14 | func NewGetLinkStatus(hubname, accountname string) *GetLinkStatus { 15 | return &GetLinkStatus{ 16 | Base: pkg.NewBase("GetLinkStatus"), 17 | Params: newGetLinkStatusParams(hubname, accountname), 18 | } 19 | } 20 | 21 | func (m *GetLinkStatus) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *GetLinkStatus) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *GetLinkStatus) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *GetLinkStatus) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *GetLinkStatus) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type GetLinkStatusParams struct { 42 | HubNameEx string `json:"HubName_Ex_str"` 43 | AccountName string `json:"AccountName_utf"` 44 | } 45 | 46 | func newGetLinkStatusParams(hubname, accountname string) *GetLinkStatusParams { 47 | return &GetLinkStatusParams{ 48 | HubNameEx: hubname, 49 | AccountName: accountname, 50 | } 51 | } 52 | 53 | func (p *GetLinkStatusParams) Tags() []string { 54 | return []string{ 55 | "HubName_Ex_str", 56 | "AccountName_utf", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/add_local_bridge.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type AddLocalBridge struct { 10 | pkg.Base 11 | Params *AddLocalBridgeParams `json:"params"` 12 | } 13 | 14 | func NewAddLocalBridge(hubNameLB, deviceName string) *AddLocalBridge { 15 | return &AddLocalBridge{ 16 | Base: pkg.NewBase("AddLocalBridge"), 17 | Params: newAddLocalBridgeParams(hubNameLB, deviceName), 18 | } 19 | } 20 | 21 | func (m *AddLocalBridge) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *AddLocalBridge) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *AddLocalBridge) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *AddLocalBridge) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *AddLocalBridge) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type AddLocalBridgeParams struct { 42 | HubNameLB string `json:"HubNameLB_str"` 43 | DeviceName string `json:"DeviceName_str"` 44 | } 45 | 46 | func newAddLocalBridgeParams(hubNameLB, deviceName string) *AddLocalBridgeParams { 47 | return &AddLocalBridgeParams{ 48 | HubNameLB: hubNameLB, 49 | DeviceName: deviceName, 50 | } 51 | } 52 | 53 | func (p *AddLocalBridgeParams) Tags() []string { 54 | return []string{ 55 | "HubNameLB_str", 56 | "DeviceName_str", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/set_link_offline.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type SetLinkOffline struct { 10 | pkg.Base 11 | Params *SetLinkOfflineParams `json:"params"` 12 | } 13 | 14 | func NewSetLinkOffline(hubname, accountname string) *SetLinkOffline { 15 | return &SetLinkOffline{ 16 | Base: pkg.NewBase("SetLinkOffline"), 17 | Params: newSetLinkOfflineParams(hubname, accountname), 18 | } 19 | } 20 | 21 | func (m *SetLinkOffline) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *SetLinkOffline) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *SetLinkOffline) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *SetLinkOffline) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *SetLinkOffline) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type SetLinkOfflineParams struct { 42 | HubName string `json:"HubName_str"` 43 | AccountName string `json:"AccountName_utf"` 44 | } 45 | 46 | func newSetLinkOfflineParams(hubname, accountname string) *SetLinkOfflineParams { 47 | return &SetLinkOfflineParams{ 48 | HubName: hubname, 49 | AccountName: accountname, 50 | } 51 | } 52 | 53 | func (p *SetLinkOfflineParams) Tags() []string { 54 | return []string{ 55 | "HubName_str", 56 | "AccountName_utf", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/enable_secure_NAT.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type EnableSecureNAT struct { 11 | pkg.Base 12 | Params *EnableSecureNATParams `json:"params"` 13 | } 14 | 15 | func (g *EnableSecureNAT) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewEnableSecureNAT(hubName string) *EnableSecureNAT { 20 | return &EnableSecureNAT{ 21 | Base: pkg.NewBase("EnableSecureNAT"), 22 | Params: newEnableSecureNATParams(hubName), 23 | } 24 | } 25 | 26 | func (g *EnableSecureNAT) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *EnableSecureNAT) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *EnableSecureNAT) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *EnableSecureNAT) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type EnableSecureNATParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newEnableSecureNATParams(hubName string) *EnableSecureNATParams { 52 | return &EnableSecureNATParams{ 53 | HubName: hubName, 54 | } 55 | } 56 | 57 | func (p *EnableSecureNATParams) Tags() []string { 58 | return []string{"HubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/disable_secure_NAT.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type DisableSecureNAT struct { 11 | pkg.Base 12 | Params *DisableSecureNATParams `json:"params"` 13 | } 14 | 15 | func (g *DisableSecureNAT) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewDisableSecureNAT(hubName string) *DisableSecureNAT { 20 | return &DisableSecureNAT{ 21 | Base: pkg.NewBase("DisableSecureNAT"), 22 | Params: newDisableSecureNATParams(hubName), 23 | } 24 | } 25 | 26 | func (g *DisableSecureNAT) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *DisableSecureNAT) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *DisableSecureNAT) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *DisableSecureNAT) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type DisableSecureNATParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newDisableSecureNATParams(hubName string) *DisableSecureNATParams { 52 | return &DisableSecureNATParams{ 53 | HubName: hubName, 54 | } 55 | } 56 | 57 | func (p *DisableSecureNATParams) Tags() []string { 58 | return []string{"HubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/get_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type GetLink struct { 11 | pkg.Base 12 | Params *GetLinkParams `json:"params"` 13 | } 14 | 15 | func NewGetLink(hubNameEx, accountName string) *GetLink { 16 | return &GetLink{ 17 | Base: pkg.NewBase("GetLink"), 18 | Params: newGetLinkParams(hubNameEx, accountName), 19 | } 20 | } 21 | 22 | func (m *GetLink) Name() string { 23 | return m.Base.Name 24 | } 25 | 26 | func (m *GetLink) GetId() int { 27 | return m.Id 28 | } 29 | 30 | func (m *GetLink) SetId(id int) { 31 | m.Base.Id = id 32 | } 33 | 34 | func (m *GetLink) Parameter() pkg.Params { 35 | return m.Params 36 | } 37 | 38 | func (m *GetLink) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(m) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type GetLinkParams struct { 48 | HubNameEx string `json:"HubName_Ex_str"` 49 | AccountName string `json:"AccountName_utf"` 50 | } 51 | 52 | func newGetLinkParams(hubNameEx, accountName string) *GetLinkParams { 53 | return &GetLinkParams{HubNameEx: hubNameEx, AccountName: accountName} 54 | } 55 | 56 | func (p *GetLinkParams) Tags() []string { 57 | return []string{ 58 | "HubName_Ex_str", 59 | "AccountName_utf", 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /methods/delete_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type DeleteLink struct { 11 | pkg.Base 12 | Params *DeleteLinkParams `json:"params"` 13 | } 14 | 15 | func NewDeleteLink(hubname, accountname string) *DeleteLink { 16 | return &DeleteLink{ 17 | Base: pkg.NewBase("DeleteLink"), 18 | Params: newDeleteLinkParams(hubname, accountname), 19 | } 20 | } 21 | func (m *DeleteLink) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *DeleteLink) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *DeleteLink) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *DeleteLink) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *DeleteLink) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(m) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type DeleteLinkParams struct { 47 | HubName string `json:"HubName_str"` 48 | AccountName string `json:"AccountName_utf"` 49 | } 50 | 51 | func newDeleteLinkParams(hubname, accountname string) *DeleteLinkParams { 52 | return &DeleteLinkParams{HubName: hubname, AccountName: accountname} 53 | } 54 | 55 | func (p *DeleteLinkParams) Tags() []string { 56 | return []string{ 57 | "HubName_str", 58 | "AccountName_utf", 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /methods/delete_local_bridge.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type DeleteLocalBridge struct { 10 | pkg.Base 11 | Params *DeleteLocalBridgeParams `json:"params"` 12 | } 13 | 14 | func NewDeleteLocalBridge(hubNameLB, deviceName string) *DeleteLocalBridge { 15 | return &DeleteLocalBridge{ 16 | Base: pkg.NewBase("DeleteLocalBridge"), 17 | Params: newDeleteLocalBridgeParams(hubNameLB, deviceName), 18 | } 19 | } 20 | 21 | func (m *DeleteLocalBridge) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *DeleteLocalBridge) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *DeleteLocalBridge) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *DeleteLocalBridge) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *DeleteLocalBridge) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type DeleteLocalBridgeParams struct { 42 | HubNameLB string `json:"HubNameLB_str"` 43 | DeviceName string `json:"DeviceName_str"` 44 | } 45 | 46 | func newDeleteLocalBridgeParams(hubNameLB, deviceName string) *DeleteLocalBridgeParams { 47 | return &DeleteLocalBridgeParams{ 48 | HubNameLB: hubNameLB, 49 | DeviceName: deviceName, 50 | } 51 | } 52 | 53 | func (p *DeleteLocalBridgeParams) Tags() []string { 54 | return []string{ 55 | "HubNameLB_str", 56 | "DeviceName_str", 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /methods/create_listener.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type CreateListener struct { 10 | pkg.Base 11 | Params *CreateListenerParams `json:"params"` 12 | } 13 | 14 | func (g *CreateListener) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewCreateListener(port int, enable bool) *CreateListener { 19 | return &CreateListener{ 20 | Base: pkg.NewBase("CreateListener"), 21 | Params: newCreateListenerParams(port, enable), 22 | } 23 | } 24 | 25 | func (g *CreateListener) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *CreateListener) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *CreateListener) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *CreateListener) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type CreateListenerParams struct { 47 | Port int `json:"Port_u32"` 48 | Enable bool `json:"Enable_bool"` 49 | } 50 | 51 | func newCreateListenerParams(port int, enable bool) *CreateListenerParams { 52 | return &CreateListenerParams{ 53 | Port: port, 54 | Enable: enable, 55 | } 56 | } 57 | 58 | func (p *CreateListenerParams) Tags() []string { 59 | return []string{"Port_u32", "Enable_bool"} 60 | } 61 | -------------------------------------------------------------------------------- /methods/enable_listener.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type EnableListener struct { 10 | pkg.Base 11 | Params *EnableListenerParams `json:"params"` 12 | } 13 | 14 | func (g *EnableListener) Parameter() pkg.Params { 15 | return g.Params 16 | } 17 | 18 | func NewEnableListener(port int, enable bool) *EnableListener { 19 | return &EnableListener{ 20 | Base: pkg.NewBase("EnableListener"), 21 | Params: newEnableListenerParams(port, enable), 22 | } 23 | } 24 | 25 | func (g *EnableListener) Name() string { 26 | return g.Base.Name 27 | } 28 | 29 | func (g *EnableListener) GetId() int { 30 | return g.Id 31 | } 32 | 33 | func (g *EnableListener) SetId(id int) { 34 | g.Base.Id = id 35 | } 36 | 37 | func (g *EnableListener) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(g) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type EnableListenerParams struct { 47 | Port int `json:"Port_u32"` 48 | Enable bool `json:"Enable_bool"` 49 | } 50 | 51 | func newEnableListenerParams(port int, enable bool) *EnableListenerParams { 52 | return &EnableListenerParams{ 53 | Port: port, 54 | Enable: enable, 55 | } 56 | } 57 | 58 | func (p *EnableListenerParams) Tags() []string { 59 | return []string{"Port_u32", "Enable_bool"} 60 | } 61 | -------------------------------------------------------------------------------- /methods/get_secure_NAT_status.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type GetSecureNATStatus struct { 11 | pkg.Base 12 | Params *GetSecureNATStatusParams `json:"params"` 13 | } 14 | 15 | func (g *GetSecureNATStatus) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewGetSecureNATStatus(hubName string) *GetSecureNATStatus { 20 | return &GetSecureNATStatus{ 21 | Base: pkg.NewBase("GetSecureNATStatus"), 22 | Params: newGetSecureNATStatusParams(hubName), 23 | } 24 | } 25 | 26 | func (g *GetSecureNATStatus) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *GetSecureNATStatus) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *GetSecureNATStatus) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *GetSecureNATStatus) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type GetSecureNATStatusParams struct { 48 | HubName string `json:"HubName_str"` 49 | } 50 | 51 | func newGetSecureNATStatusParams(hubName string) *GetSecureNATStatusParams { 52 | return &GetSecureNATStatusParams{ 53 | HubName: hubName, 54 | } 55 | } 56 | 57 | func (p *GetSecureNATStatusParams) Tags() []string { 58 | return []string{"HubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/get_secure_NAT_option.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type GetSecureNATOption struct { 11 | pkg.Base 12 | Params *GetSecureNATOptionParams `json:"params"` 13 | } 14 | 15 | func (g *GetSecureNATOption) Parameter() pkg.Params { 16 | return g.Params 17 | } 18 | 19 | func NewGetSecureNATOption(rpcHubName string) *GetSecureNATOption { 20 | return &GetSecureNATOption{ 21 | Base: pkg.NewBase("GetSecureNATOption"), 22 | Params: newGetSecureNATOptionParams(rpcHubName), 23 | } 24 | } 25 | 26 | func (g *GetSecureNATOption) Name() string { 27 | return g.Base.Name 28 | } 29 | 30 | func (g *GetSecureNATOption) GetId() int { 31 | return g.Id 32 | } 33 | 34 | func (g *GetSecureNATOption) SetId(id int) { 35 | g.Base.Id = id 36 | } 37 | 38 | func (g *GetSecureNATOption) Marshall() ([]byte, error) { 39 | data, err := json.Marshal(g) 40 | if err != nil { 41 | return nil, err 42 | } 43 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 44 | return res, nil 45 | } 46 | 47 | type GetSecureNATOptionParams struct { 48 | RpcHubName string `json:"RpcHubName_str"` 49 | } 50 | 51 | func newGetSecureNATOptionParams(rpcHubName string) *GetSecureNATOptionParams { 52 | return &GetSecureNATOptionParams{ 53 | RpcHubName: rpcHubName, 54 | } 55 | } 56 | 57 | func (p *GetSecureNATOptionParams) Tags() []string { 58 | return []string{"RpcHubName_str"} 59 | } 60 | -------------------------------------------------------------------------------- /methods/rename_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | 7 | "github.com/terassyi/go-softether-api/pkg" 8 | ) 9 | 10 | type RenameLink struct { 11 | pkg.Base 12 | Params *RenameLinkParams `json:"params"` 13 | } 14 | 15 | func NewRenameLink(hubname, oldAccountname, newAccountname string) *RenameLink { 16 | return &RenameLink{ 17 | Base: pkg.NewBase("RenameLink"), 18 | Params: newRenameLinkParams(hubname, oldAccountname, newAccountname), 19 | } 20 | } 21 | func (m *RenameLink) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *RenameLink) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *RenameLink) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *RenameLink) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *RenameLink) Marshall() ([]byte, error) { 38 | data, err := json.Marshal(m) 39 | if err != nil { 40 | return nil, err 41 | } 42 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 43 | return res, nil 44 | } 45 | 46 | type RenameLinkParams struct { 47 | HubName string `json:"HubName_str"` 48 | OldAccountName string `json:"OldAccountName_utf"` 49 | NewAccountName string `json:"NewAccountName_utf"` 50 | } 51 | 52 | func newRenameLinkParams(hubname, oldAccountname, newAccountname string) *RenameLinkParams { 53 | return &RenameLinkParams{HubName: hubname, OldAccountName: oldAccountname, NewAccountName: newAccountname} 54 | } 55 | 56 | func (p *RenameLinkParams) Tags() []string { 57 | return []string{ 58 | "HubName_str", 59 | "OldAccountName_utf", 60 | "NewAccountName_utf", 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pkg/util.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | import ( 4 | "encoding/json" 5 | "strings" 6 | "time" 7 | ) 8 | 9 | func StructToMap(params Params) (map[string]interface{}, error) { 10 | data, err := json.Marshal(params) 11 | if err != nil { 12 | return nil, err 13 | } 14 | dataMap := make(map[string]interface{}) 15 | if err := json.Unmarshal(data, &dataMap); err != nil { 16 | return nil, err 17 | } 18 | return splitTypes(dataMap), nil 19 | } 20 | 21 | // params typ must be empty. 22 | func MapToStruct(data map[string]interface{}, typ Params) error { 23 | bytes, err := json.Marshal(data) 24 | if err != nil { 25 | return err 26 | } 27 | return json.Unmarshal(bytes, typ) 28 | } 29 | 30 | func splitTypes(params map[string]interface{}) map[string]interface{} { 31 | data := make(map[string]interface{}) 32 | for k, v := range params { 33 | s := strings.Split(k, "_") 34 | if len(s) > 2 { 35 | t := s[0] 36 | for i := 1; i < len(s)-1; i++ { 37 | t += "_" + s[i] 38 | } 39 | data[t] = v 40 | continue 41 | } 42 | data[s[0]] = v 43 | } 44 | return data 45 | } 46 | 47 | func ValidateType(typ string, val interface{}) bool { 48 | switch typ { 49 | case str, utf, bin, ip: 50 | switch val.(type) { 51 | case string: 52 | return true 53 | default: 54 | return false 55 | } 56 | case u32, u64: 57 | switch val.(type) { 58 | case int: 59 | return true 60 | default: 61 | return false 62 | } 63 | case boolean: 64 | switch val.(type) { 65 | case bool: 66 | return true 67 | default: 68 | return false 69 | } 70 | case date: 71 | switch val.(type) { 72 | case time.Time: 73 | return true 74 | default: 75 | return false 76 | } 77 | default: 78 | return false 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /methods/set_hub.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type SetHub struct { 9 | pkg.Base 10 | Params *SetHubParams `json:"params"` 11 | } 12 | 13 | func NewSetHub(name, password string, online bool) *SetHub { 14 | return &SetHub{ 15 | Base: pkg.NewBase("SetHub"), 16 | Params: newSetHubParams(name, password, online), 17 | } 18 | } 19 | 20 | func (m *SetHub) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *SetHub) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *SetHub) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *SetHub) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *SetHub) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type SetHubParams struct { 41 | HubName string `json:"HubName_str"` 42 | AdminPasswordPlainText string `json:"AdminPasswordPlainText_str"` 43 | Online bool `json:"Online_bool"` 44 | MaxSession int `json:"MaxSession_u32"` 45 | NoEnum bool `json:"NoEnum_bool"` 46 | HubType int `json:"HubType_u32"` 47 | } 48 | 49 | func newSetHubParams(name, password string, online bool) *SetHubParams { 50 | return &SetHubParams{ 51 | HubName: name, 52 | AdminPasswordPlainText: password, 53 | Online: online, 54 | MaxSession: 0, 55 | NoEnum: false, 56 | HubType: 0, 57 | } 58 | } 59 | 60 | func (p *SetHubParams) Tags() []string { 61 | return []string{ 62 | "HubName_str", 63 | "AdminPasswordPlainText_str", 64 | "Online_bool", 65 | "MaxSession_u32", 66 | "NoEnum_bool", 67 | "HubType_u32", 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /methods/create_hub.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/terassyi/go-softether-api/pkg" 6 | ) 7 | 8 | type CreateHub struct { 9 | pkg.Base 10 | Params *CreateHubParams `json:"params"` 11 | } 12 | 13 | func NewCreateHub(name, password string, online bool) *CreateHub { 14 | return &CreateHub{ 15 | Base: pkg.NewBase("CreateHub"), 16 | Params: newCreateHubParams(name, password, online), 17 | } 18 | } 19 | 20 | func (m *CreateHub) Name() string { 21 | return m.Base.Name 22 | } 23 | 24 | func (m *CreateHub) GetId() int { 25 | return m.Id 26 | } 27 | 28 | func (m *CreateHub) SetId(id int) { 29 | m.Base.Id = id 30 | } 31 | 32 | func (m *CreateHub) Parameter() pkg.Params { 33 | return m.Params 34 | } 35 | 36 | func (m *CreateHub) Marshall() ([]byte, error) { 37 | return json.Marshal(m) 38 | } 39 | 40 | type CreateHubParams struct { 41 | HubName string `json:"HubName_str"` 42 | AdminPasswordPlainText string `json:"AdminPasswordPlainText_str"` 43 | Online bool `json:"Online_bool"` 44 | MaxSession int `json:"MaxSession_u32"` 45 | NoEnum bool `json:"NoEnum_bool"` 46 | HubType int `json:"HubType_u32"` 47 | } 48 | 49 | func newCreateHubParams(name, password string, online bool) *CreateHubParams { 50 | return &CreateHubParams{ 51 | HubName: name, 52 | AdminPasswordPlainText: password, 53 | Online: online, 54 | MaxSession: 0, 55 | NoEnum: false, 56 | HubType: 0, 57 | } 58 | } 59 | 60 | func (p *CreateHubParams) Tags() []string { 61 | return []string{ 62 | "HubName_str", 63 | "AdminPasswordPlainText_str", 64 | "Online_bool", 65 | "MaxSession_u32", 66 | "NoEnum_bool", 67 | "HubType_u32", 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SoftEther VPN Server JSON-RPC API in Golang 2 | 3 | This is the SoftEther VPN Server JSON-RPC API wrapper in Go. 4 | See a [document](https://github.com/SoftEtherVPN/SoftEtherVPN/tree/master/developer_tools/vpnserver-jsonrpc-clients/) for more information. 5 | 6 | ## support 7 | 8 | supported API methods 9 | 10 | - Test 11 | - GetServerInfo 12 | - GetServerStatus 13 | - CreateListener 14 | - EnumListener 15 | - DeleteListener 16 | - EnableListener 17 | - SetServerPassword 18 | - CreateHub 19 | - SetHub 20 | - EnumHub 21 | - DeleteHub 22 | - GetHubStatus 23 | - SetHubOnline 24 | - EnumConnection 25 | - DisconnectConnection 26 | - GetConnectionInfo 27 | - CreateLink 28 | - GetLink 29 | - SetLink 30 | - EnumLink 31 | - SetLinkOnline 32 | - SetLinkOffline 33 | - DeleteLink 34 | - CreateUser 35 | - SetUser 36 | - GetUser 37 | - EnumUser 38 | - EnableSecureNAT 39 | - DisableSecureNAT 40 | - SetSecureNATOption 41 | - GetSecureNATOption 42 | - EnumNAT 43 | - EnumDHCP 44 | - EnumEthernet 45 | - AddLocalBridge 46 | - DeleteLocalBridge 47 | - EnumLocalBridge 48 | - GetBridgeSupport 49 | 50 | ## Usage 51 | 52 | To use this package, import this package like bellow. 53 | 54 | ```go 55 | import softether "github.com/terassyi/go-softether-api" 56 | ``` 57 | 58 | First, you have to create a new Api instance. 59 | 60 | ```go 61 | api := softether.New("localhost", 443, "default", "password") 62 | ``` 63 | 64 | Second, You can create api methods you want to call. 65 | API methods are in methods package. These methods implement the `Method` interface. 66 | For example, to call `Test` method. 67 | 68 | ```go 69 | method := methods.NewTest() 70 | ``` 71 | 72 | And execute `api.Call()`. Then, result will return as `map[string](interface{})`. 73 | 74 | ```go 75 | res, err := api.Call(method) 76 | if err != nil { 77 | panic(err) 78 | } 79 | fmt.Println(res) 80 | ``` 81 | 82 | ## Future works 83 | 84 | I'm making api methods as needed. Other methods will be supported. 85 | -------------------------------------------------------------------------------- /api.go: -------------------------------------------------------------------------------- 1 | package softetherapi 2 | 3 | import ( 4 | "bytes" 5 | "crypto/tls" 6 | "encoding/json" 7 | "fmt" 8 | "github.com/terassyi/go-softether-api/pkg" 9 | "io/ioutil" 10 | "net/http" 11 | ) 12 | 13 | //to handle softether vpn server json-rpc api 14 | type Api struct { 15 | Host string 16 | Port int 17 | Hub string 18 | Password string 19 | id Id 20 | conn *http.Client 21 | } 22 | 23 | // Id interface is used for request id 24 | type Id interface { 25 | Incl() 26 | Describe() int 27 | } 28 | 29 | // id struct is the implement of Id interface 30 | type id int 31 | 32 | func initId() Id { 33 | return id(0) 34 | } 35 | 36 | // This method increment an id 37 | func (i id) Incl() { 38 | i += 1 39 | } 40 | 41 | func (i id) Describe() int { 42 | return int(i) 43 | } 44 | 45 | func New(host string, port int, hub, password string) *Api { 46 | return &Api{ 47 | Host: host, 48 | Port: port, 49 | Hub: hub, 50 | Password: password, 51 | id: initId(), 52 | conn: connect(), 53 | } 54 | } 55 | 56 | func (api *Api) entrypoint() string { 57 | return fmt.Sprintf("https://%s:%d/api", api.Host, api.Port) 58 | } 59 | 60 | func (api *Api) Call(method pkg.Method) (map[string]interface{}, error) { 61 | api.id.Incl() 62 | method.SetId(api.id.Describe()) 63 | body, err := method.Marshall() 64 | fmt.Println(string(body)) 65 | if err != nil { 66 | return nil, fmt.Errorf("[error] failed to marshall request: %v", err) 67 | } 68 | req, err := http.NewRequest("POST", api.entrypoint(), bytes.NewBuffer(body)) 69 | if err != nil { 70 | return nil, fmt.Errorf("[error] failed to create new http request: %v", err) 71 | } 72 | // set headers 73 | req.Header.Set("Content-Type", "application/json") 74 | req.Header.Set("X-VPNADMIN-HUBNAME", api.Hub) 75 | req.Header.Set("X-VPNADMIN-PASSWORD", api.Password) 76 | // send an api request 77 | res, err := api.conn.Do(req) 78 | if err != nil { 79 | return nil, fmt.Errorf("[error] failed to call: %v", err) 80 | } 81 | return validateResponse(res) 82 | } 83 | 84 | func connect() *http.Client { 85 | tl := &http.Transport{ 86 | TLSClientConfig: &tls.Config{ 87 | InsecureSkipVerify: true, 88 | }, 89 | } 90 | return &http.Client{Transport: tl} 91 | } 92 | 93 | func validateResponse(res *http.Response) (map[string]interface{}, error) { 94 | defer res.Body.Close() 95 | body, err := ioutil.ReadAll(res.Body) 96 | if err != nil { 97 | return nil, fmt.Errorf("[error] failed to read: %v", err) 98 | } 99 | fmt.Println(string(body)) 100 | b := make(map[string]interface{}) 101 | err = json.Unmarshal(body, &b) 102 | if err != nil { 103 | return nil, err 104 | } 105 | if _, ok := b["result"]; ok { 106 | return b["result"].(map[string]interface{}), nil 107 | } 108 | return nil, fmt.Errorf("%v", b["error"]) 109 | } 110 | -------------------------------------------------------------------------------- /methods/set_secure_NAT_option.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "encoding/json" 5 | 6 | "github.com/terassyi/go-softether-api/pkg" 7 | ) 8 | 9 | type SetSecureNATOption struct { 10 | pkg.Base 11 | Params *SetSecureNATOptionParams `json:"params"` 12 | } 13 | 14 | func NewSetSecureNATOption(rpcHubName string) *SetSecureNATOption { 15 | return &SetSecureNATOption{ 16 | Base: pkg.NewBase("SetSecureNATOption"), 17 | Params: newSetSecureNATOptionParams(rpcHubName), 18 | } 19 | } 20 | 21 | func (m *SetSecureNATOption) Name() string { 22 | return m.Base.Name 23 | } 24 | 25 | func (m *SetSecureNATOption) GetId() int { 26 | return m.Id 27 | } 28 | 29 | func (m *SetSecureNATOption) SetId(id int) { 30 | m.Base.Id = id 31 | } 32 | 33 | func (m *SetSecureNATOption) Parameter() pkg.Params { 34 | return m.Params 35 | } 36 | 37 | func (m *SetSecureNATOption) Marshall() ([]byte, error) { 38 | return json.Marshal(m) 39 | } 40 | 41 | type SetSecureNATOptionParams struct { 42 | RpcHubName string `json:"RpcHubName_str"` 43 | MacAddressBin string `json:"MacAddress_bin"` 44 | Ip string `json:"Ip_ip"` 45 | MaskIp string `json:"Mask_ip"` 46 | UseNat bool `json:"UseNat_bool"` 47 | Mtu int `json:"Mtu_u32"` 48 | NatTcpTimeout int `json:"NatTcpTimeout_u32"` 49 | NatUdpTimeout int `json:"NatUdpTimeout_u32"` 50 | UseDhcp bool `json:"UseDhcp_bool"` 51 | DhcpLeaseIPStart string `json:"DhcpLeaseIPStart_ip"` 52 | DhcpLeaseIPEnd string `json:"DhcpLeaseIPEnd_ip"` 53 | DhcpSubnetMask string `json:"DhcpSubnetMask_ip"` 54 | DhcpExpireTimeSpan int `json:"DhcpExpireTimeSpan_u32"` 55 | DhcpGatewayAddress string `json:"DhcpGatewayAddress_ip"` 56 | DhcpDnsServerAddress string `json:"DhcpDnsServerAddress_ip"` 57 | DhcpDnsServerAddress2 string `json:"DhcpDnsServerAddress2_ip"` 58 | DhcpDomainName string `json:"DhcpDomainName_str"` 59 | SaveLog bool `json:"SaveLog_bool"` 60 | ApplyDhcpPushRoutes bool `json:"ApplyDhcpPushRoutes_bool"` 61 | DhcpPushRoutes string `json:"DhcpPushRoutes_str"` 62 | } 63 | 64 | func newSetSecureNATOptionParams(rpcHubName string) *SetSecureNATOptionParams { 65 | return &SetSecureNATOptionParams{ 66 | RpcHubName: rpcHubName, 67 | } 68 | } 69 | 70 | func (p *SetSecureNATOptionParams) Tags() []string { 71 | return []string{ 72 | "RpcHubName_str", 73 | "MacAddress_bin", 74 | "Ip_ip", 75 | "Mask_ip", 76 | "UseNat_bool", 77 | "Mtu_u32", 78 | "NatTcpTimeout_u32", 79 | "NatUdpTimeout_u32", 80 | "UseDhcp_bool", 81 | "DhcpLeaseIPStart_ip", 82 | "DhcpLeaseIPEnd_ip", 83 | "DhcpSubnetMask_ip", 84 | "DhcpExpireTimeSpan_u32", 85 | "DhcpGatewayAddress_ip", 86 | "DhcpDnsServerAddress_ip", 87 | "DhcpDnsServerAddress2_ip", 88 | "DhcpDomainName_str", 89 | "SaveLog_bool", 90 | "ApplyDhcpPushRoutes_bool", 91 | "DhcpPushRoutes_str", 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /pkg/util_test.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | type testParams struct { 9 | Field1 string `json:"Field1_str"` 10 | Field2 int `json:"Field2_u32"` 11 | Field3 bool `json:"Field3_bool"` 12 | Field_a bool `json:"Field_a_bool"` 13 | FieldList []int `json:"FieldList"` 14 | } 15 | 16 | func (p *testParams) Empty() *testParams { 17 | return &testParams{} 18 | } 19 | 20 | func (p *testParams) Tags() []string { 21 | return []string{ 22 | "Field1_str", 23 | "Field2_u32", 24 | "Field3_bool", 25 | "Field_a_bool", 26 | "FieldList", 27 | } 28 | } 29 | 30 | func (p *testParams) Set(key string, val interface{}) error { 31 | //n := &testParams{} 32 | //m, err := StructToMap(p) 33 | //if err != nil { 34 | // return err 35 | //} 36 | //m[key] = val 37 | //if err = MapToStruct(m, n); err != nil { 38 | // return err 39 | //} 40 | //*p = *n 41 | switch key { 42 | case "Field1": 43 | p.Field1 = val.(string) 44 | case "Field2": 45 | p.Field2 = val.(int) 46 | case "Field3": 47 | p.Field3 = val.(bool) 48 | case "Field_a": 49 | p.Field_a = val.(bool) 50 | case "FieldList": 51 | p.FieldList = val.([]int) 52 | default: 53 | return fmt.Errorf("no such parameter") 54 | 55 | } 56 | return nil 57 | } 58 | 59 | func (p *testParams) Get(key string) (interface{}, error) { 60 | data, err := StructToMap(p) 61 | if err != nil { 62 | return nil, err 63 | } 64 | if data[key] == nil { 65 | return nil, fmt.Errorf("no such parameter") 66 | } 67 | return data[key], nil 68 | } 69 | 70 | func TestStructToMap(t *testing.T) { 71 | p := &testParams{ 72 | Field1: "field1", 73 | Field2: 1, 74 | Field3: false, 75 | } 76 | wanted := make(map[string]interface{}) 77 | wanted["Field1"] = p.Field1 78 | wanted["Field2"] = p.Field2 79 | wanted["Field3"] = p.Field3 80 | m, err := StructToMap(p) 81 | if err != nil { 82 | t.Fatal(err) 83 | } 84 | if m["Field1"] != wanted["Field1"] { 85 | t.Fatalf("actual: %v", m) 86 | } 87 | } 88 | 89 | func TestStructToMapNoField(t *testing.T) { 90 | p := &testParams{ 91 | Field1: "field1", 92 | Field2: 1, 93 | Field3: false, 94 | } 95 | wanted := make(map[string]interface{}) 96 | wanted["Field1"] = p.Field1 97 | wanted["Field2"] = p.Field2 98 | wanted["Field3"] = p.Field3 99 | wanted["Field4"] = "dont exist" 100 | fmt.Println(wanted) 101 | m, err := StructToMap(p) 102 | if err != nil { 103 | t.Fatal(err) 104 | } 105 | if m["Field1"] != wanted["Field1"] { 106 | t.Fatalf("actual: %v", m) 107 | } 108 | if m["Field4"] != nil { 109 | t.Fatalf("found invalid field") 110 | } 111 | } 112 | 113 | func TestSplitType(t *testing.T) { 114 | p := &testParams{ 115 | Field1: "field1", 116 | Field2: 1, 117 | Field3: false, 118 | Field_a: true, 119 | FieldList: []int{0, 1}, 120 | } 121 | d, err := StructToMap(p) 122 | if err != nil { 123 | t.Fatal(err) 124 | } 125 | if d["Field_a"] != true { 126 | t.Fatalf("actual: %v", d) 127 | } 128 | fmt.Println(d) 129 | tmp := d["FieldList"].([]interface{}) 130 | v := tmp[1] 131 | wanted := 1 132 | if int(v.(float64)) != 1 { 133 | t.Fatalf("failed - wanted: %v - actual: %v", wanted, v) 134 | } 135 | } 136 | 137 | func TestMapToStruct(t *testing.T) { 138 | p := &testParams{ 139 | Field1: "field1", 140 | Field2: 1, 141 | Field3: false, 142 | Field_a: true, 143 | FieldList: []int{0, 1}, 144 | } 145 | res, err := p.Get("Field2") 146 | if err != nil { 147 | t.Fatal(err) 148 | } 149 | resInt := int(res.(float64)) 150 | wanted := 1 151 | if resInt != wanted { 152 | t.Fatalf("actual: %v", res) 153 | } 154 | } 155 | 156 | func TestMapToStructModify(t *testing.T) { 157 | p := &testParams{ 158 | Field1: "field1", 159 | Field2: 1, 160 | Field3: false, 161 | Field_a: true, 162 | FieldList: []int{0, 1}, 163 | } 164 | if err := p.Set("FieldList", []int{1, 2}); err != nil { 165 | t.Fatal(err) 166 | } 167 | res, err := p.Get("FieldList") 168 | if err != nil { 169 | t.Fatal(err) 170 | } 171 | resString := res.([]int) 172 | wanted := []int{1, 2} 173 | if resString[0] != wanted[0] { 174 | t.Fatalf("actual: %v", resString) 175 | } 176 | } 177 | -------------------------------------------------------------------------------- /pkg/softether_jsonrpc.go: -------------------------------------------------------------------------------- 1 | package pkg 2 | 3 | /* CreateUser input 4 | { 5 | "jsonrpc": "2.0", 6 | "id": "rpc_call_id", 7 | "method": "CreateUser", 8 | "params": { 9 | "HubName_str": "hubname", 10 | "Name_str": "name", 11 | "Realname_utf": "realname", 12 | "Note_utf": "note", 13 | "ExpireTime_dt": "2020-08-01T12:24:36.123", 14 | "AuthType_u32": 0, 15 | "Auth_Password_str": "auth_password", 16 | "UserX_bin": "SGVsbG8gV29ybGQ=", 17 | "Serial_bin": "SGVsbG8gV29ybGQ=", 18 | "CommonName_utf": "auth_rootcert_commonname", 19 | "RadiusUsername_utf": "auth_radius_radiususername", 20 | "NtUsername_utf": "auth_nt_ntusername", 21 | "UsePolicy_bool": false, 22 | "policy:Access_bool": false, 23 | "policy:DHCPFilter_bool": false, 24 | "policy:DHCPNoServer_bool": false, 25 | "policy:DHCPForce_bool": false, 26 | "policy:NoBridge_bool": false, 27 | "policy:NoRouting_bool": false, 28 | "policy:CheckMac_bool": false, 29 | "policy:CheckIP_bool": false, 30 | "policy:ArpDhcpOnly_bool": false, 31 | "policy:PrivacyFilter_bool": false, 32 | "policy:NoServer_bool": false, 33 | "policy:NoBroadcastLimiter_bool": false, 34 | "policy:MonitorPort_bool": false, 35 | "policy:MaxConnection_u32": 0, 36 | "policy:TimeOut_u32": 0, 37 | "policy:MaxMac_u32": 0, 38 | "policy:MaxIP_u32": 0, 39 | "policy:MaxUpload_u32": 0, 40 | "policy:MaxDownload_u32": 0, 41 | "policy:FixPassword_bool": false, 42 | "policy:MultiLogins_u32": 0, 43 | "policy:NoQoS_bool": false, 44 | "policy:RSandRAFilter_bool": false, 45 | "policy:RAFilter_bool": false, 46 | "policy:DHCPv6Filter_bool": false, 47 | "policy:DHCPv6NoServer_bool": false, 48 | "policy:NoRoutingV6_bool": false, 49 | "policy:CheckIPv6_bool": false, 50 | "policy:NoServerV6_bool": false, 51 | "policy:MaxIPv6_u32": 0, 52 | "policy:NoSavePassword_bool": false, 53 | "policy:AutoDisconnect_u32": 0, 54 | "policy:FilterIPv4_bool": false, 55 | "policy:FilterIPv6_bool": false, 56 | "policy:FilterNonIP_bool": false, 57 | "policy:NoIPv6DefaultRouterInRA_bool": false, 58 | "policy:NoIPv6DefaultRouterInRAWhenIPv6_bool": false, 59 | "policy:VLanId_u32": 0, 60 | "policy:Ver3_bool": false 61 | } 62 | } 63 | */ 64 | 65 | /* CreateUser output 66 | { 67 | "jsonrpc": "2.0", 68 | "id": "rpc_call_id", 69 | "result": { 70 | "HubName_str": "hubname", 71 | "Name_str": "name", 72 | "GroupName_str": "groupname", 73 | "Realname_utf": "realname", 74 | "Note_utf": "note", 75 | "CreatedTime_dt": "2020-08-01T12:24:36.123", 76 | "UpdatedTime_dt": "2020-08-01T12:24:36.123", 77 | "ExpireTime_dt": "2020-08-01T12:24:36.123", 78 | "AuthType_u32": 0, 79 | "Auth_Password_str": "auth_password", 80 | "UserX_bin": "SGVsbG8gV29ybGQ=", 81 | "Serial_bin": "SGVsbG8gV29ybGQ=", 82 | "CommonName_utf": "auth_rootcert_commonname", 83 | "RadiusUsername_utf": "auth_radius_radiususername", 84 | "NtUsername_utf": "auth_nt_ntusername", 85 | "NumLogin_u32": 0, 86 | "Recv.BroadcastBytes_u64": 0, 87 | "Recv.BroadcastCount_u64": 0, 88 | "Recv.UnicastBytes_u64": 0, 89 | "Recv.UnicastCount_u64": 0, 90 | "Send.BroadcastBytes_u64": 0, 91 | "Send.BroadcastCount_u64": 0, 92 | "Send.UnicastBytes_u64": 0, 93 | "Send.UnicastCount_u64": 0, 94 | "UsePolicy_bool": false, 95 | "policy:Access_bool": false, 96 | "policy:DHCPFilter_bool": false, 97 | "policy:DHCPNoServer_bool": false, 98 | "policy:DHCPForce_bool": false, 99 | "policy:NoBridge_bool": false, 100 | "policy:NoRouting_bool": false, 101 | "policy:CheckMac_bool": false, 102 | "policy:CheckIP_bool": false, 103 | "policy:ArpDhcpOnly_bool": false, 104 | "policy:PrivacyFilter_bool": false, 105 | "policy:NoServer_bool": false, 106 | "policy:NoBroadcastLimiter_bool": false, 107 | "policy:MonitorPort_bool": false, 108 | "policy:MaxConnection_u32": 0, 109 | "policy:TimeOut_u32": 0, 110 | "policy:MaxMac_u32": 0, 111 | "policy:MaxIP_u32": 0, 112 | "policy:MaxUpload_u32": 0, 113 | "policy:MaxDownload_u32": 0, 114 | "policy:FixPassword_bool": false, 115 | "policy:MultiLogins_u32": 0, 116 | "policy:NoQoS_bool": false, 117 | "policy:RSandRAFilter_bool": false, 118 | "policy:RAFilter_bool": false, 119 | "policy:DHCPv6Filter_bool": false, 120 | "policy:DHCPv6NoServer_bool": false, 121 | "policy:NoRoutingV6_bool": false, 122 | "policy:CheckIPv6_bool": false, 123 | "policy:NoServerV6_bool": false, 124 | "policy:MaxIPv6_u32": 0, 125 | "policy:NoSavePassword_bool": false, 126 | "policy:AutoDisconnect_u32": 0, 127 | "policy:FilterIPv4_bool": false, 128 | "policy:FilterIPv6_bool": false, 129 | "policy:FilterNonIP_bool": false, 130 | "policy:NoIPv6DefaultRouterInRA_bool": false, 131 | "policy:NoIPv6DefaultRouterInRAWhenIPv6_bool": false, 132 | "policy:VLanId_u32": 0, 133 | "policy:Ver3_bool": false 134 | } 135 | } 136 | */ 137 | -------------------------------------------------------------------------------- /methods/set_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "reflect" 7 | 8 | "github.com/terassyi/go-softether-api/pkg" 9 | ) 10 | 11 | type SetLink struct { 12 | pkg.Base 13 | Params *SetLinkParams `json:"params"` 14 | } 15 | 16 | func (g *SetLink) Parameter() pkg.Params { 17 | return g.Params 18 | } 19 | 20 | func NewSetLink(hubNameEx, accountName string) *SetLink { 21 | return &SetLink{ 22 | Base: pkg.NewBase("SetLink"), 23 | Params: newSetLinkParmas(hubNameEx, accountName), 24 | } 25 | } 26 | 27 | func (g *SetLink) Name() string { 28 | return g.Base.Name 29 | } 30 | 31 | func (g *SetLink) GetId() int { 32 | return g.Id 33 | } 34 | 35 | func (g *SetLink) SetId(id int) { 36 | g.Base.Id = id 37 | } 38 | 39 | func (g *SetLink) Marshall() ([]byte, error) { 40 | data, err := json.Marshal(g) 41 | if err != nil { 42 | return nil, err 43 | } 44 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 45 | return res, nil 46 | } 47 | 48 | type SetLinkParams struct { 49 | HubNameEx string `json:"HubName_Ex_str"` 50 | CheckServerCert bool `json:"CheckServerCert_bool"` 51 | AccountName string `json:"AccountName_utf"` 52 | Hostname string `json:"Hostname_str"` 53 | Port int `json:"Port_u32"` 54 | ProxyType int `json:"ProxyType_u32"` 55 | HubName string `json:"HubName_str"` 56 | MaxConnection int `json:"MaxConnection_u32"` 57 | UseEncrypt bool `json:"UseEncrypt_bool"` 58 | UseCompress bool `json:"UseCompress_bool"` 59 | HalfConnection bool `json:"HalfConnection_bool"` 60 | AdditionalConnectionInterval int `json:"AdditionalConnectionInterval_u32"` 61 | ConnectionDisconnectSpan int `json:"ConnectionDisconnectSpan_u32"` 62 | AuthType int `json:"AuthType_u32"` 63 | Username string `json:"Username_str"` 64 | HashedPassword string `json:"HashedPassword_bin"` 65 | PlainPassword string `json:"PlainPassword_str"` 66 | ClientX string `json:"ClientX_bin"` 67 | ClientK string `json:"ClientK_bin"` 68 | SetLinkPolicy 69 | } 70 | 71 | func newSetLinkParmas(hubNameEx, accountName string) *SetLinkParams { 72 | return &SetLinkParams{ 73 | HubNameEx: hubNameEx, 74 | AccountName: accountName, 75 | } 76 | } 77 | 78 | type SetLinkPolicy struct { 79 | DHCPFilter bool `json:"policy:DHCPFilter_bool"` 80 | DHCPNoServer bool `json:"policy:DHCPNoServer_bool"` 81 | DHCPForce bool `json:"policy:DHCPForce_bool"` 82 | CheckMac bool `json:"SecPol_CheckMac_bool"` 83 | CheckIP bool `json:"SecPol_CheckIP_bool"` 84 | ArpDhcpOnly bool `json:"policy:ArpDhcpOnly_bool"` 85 | PrivacyFilter bool `json:"policy:PrivacyFilter_bool"` 86 | NoServer bool `json:"policy:NoServer_bool"` 87 | NoBroadcastLimiter bool `json:"policy:NoBroadcastLimiter_bool"` 88 | MaxMac int `json:"policy:MaxMac_u32"` 89 | MaxIP int `json:"policy:MaxIP_u32"` 90 | MaxUpload int `json:"policy:MaxUpload_u32"` 91 | MaxDownload int `json:"policy:MaxDownload_u32"` 92 | RSandRAFilter bool `json:"policy:RSandRAFilter_bool"` 93 | RAFilter bool `json:"SecPol_RAFilter_bool"` 94 | DHCPv6Filter bool `json:"policy:DHCPv6Filter_bool"` 95 | DHCPv6NoServer bool `json:"policy:DHCPv6NoServer_bool"` 96 | CheckIPv6 bool `json:"SecPol_CheckIPv6_bool"` 97 | NoServerV6 bool `json:"policy:NoServerV6_bool"` 98 | MaxIPv6 int `json:"policy:MaxIPv6_u32"` 99 | FilterIPv4 bool `json:"policy:FilterIPv4_bool"` 100 | FilterIPv6 bool `json:"policy:FilterIPv6_bool"` 101 | FilterNonIP bool `json:"policy:FilterNonIP_bool"` 102 | NoIPv6DefaultRouterInRA bool `json:"policy:NoIPv6DefaultRouterInRA_bool"` 103 | VLanId int `json:"policy:VLanId_u32"` 104 | Ver3 bool `json:"policy:Ver3_bool"` 105 | } 106 | 107 | func (pol *SetLinkPolicy) Tags() []string { 108 | tmp := SetLinkPolicy{} 109 | t := reflect.TypeOf(tmp) 110 | var tags []string 111 | for i := 0; i < t.NumField(); i++ { 112 | tag := t.Field(i).Tag.Get("json") 113 | tags = append(tags, tag) 114 | } 115 | return tags 116 | } 117 | 118 | func (p *SetLinkParams) Tags() []string { 119 | tags := []string{ 120 | "HubName_Ex_str", 121 | "CheckServerCert_bool", 122 | "AccountName_utf", 123 | "Hostname_str", 124 | "Port_u32", 125 | "ProxyType_u32", 126 | "HubName_str", 127 | "MaxConnection_u32", 128 | "UseEncrypt_bool", 129 | "UseCompress_bool", 130 | "HalfConnection_bool", 131 | "AdditionalConnectionInterval_u32", 132 | "ConnectionDisconnectSpan_u32", 133 | "AuthType_u32", 134 | "Username_str", 135 | "HashedPassword_bin", 136 | "PlainPassword_str", 137 | "ClientX_bin", 138 | "ClientK_bin", 139 | } 140 | tags = append(tags, p.SetLinkPolicy.Tags()...) 141 | return tags 142 | } 143 | -------------------------------------------------------------------------------- /methods/create_link.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "reflect" 7 | 8 | "github.com/terassyi/go-softether-api/pkg" 9 | ) 10 | 11 | type CreateLink struct { 12 | pkg.Base 13 | Params *CreateLinkParams `json:"params"` 14 | } 15 | 16 | func NewCreateLink(hubNameEx, accountName string) *CreateLink { 17 | return &CreateLink{ 18 | Base: pkg.NewBase("CreateLink"), 19 | Params: newCreateLinkParams(hubNameEx, accountName), 20 | } 21 | } 22 | 23 | func (m *CreateLink) Name() string { 24 | return m.Base.Name 25 | } 26 | 27 | func (m *CreateLink) GetId() int { 28 | return m.Id 29 | } 30 | 31 | func (m *CreateLink) SetId(id int) { 32 | m.Base.Id = id 33 | } 34 | 35 | func (m *CreateLink) Parameter() pkg.Params { 36 | return m.Params 37 | } 38 | 39 | func (m *CreateLink) Marshall() ([]byte, error) { 40 | data, err := json.Marshal(m) 41 | if err != nil { 42 | return nil, err 43 | } 44 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 45 | return res, nil 46 | } 47 | 48 | type CreateLinkParams struct { 49 | HubNameEx string `json:"HubName_Ex_str"` 50 | CheckServerCert bool `json:"CheckServerCert_bool"` 51 | AccountName string `json:"AccountName_utf"` 52 | Hostname string `json:"Hostname_str"` 53 | Port int `json:"Port_u32"` 54 | ProxyType int `json:"ProxyType_u32"` 55 | HubName string `json:"HubName_str"` 56 | MaxConnection int `json:"MaxConnection_u32"` 57 | UseEncrypt bool `json:"UseEncrypt_bool"` 58 | UseCompress bool `json:"UseCompress_bool"` 59 | HalfConnection bool `json:"HalfConnection_bool"` 60 | AdditionalConnectionInterval int `json:"AdditionalConnectionInterval_u32"` 61 | ConnectionDisconnectSpan int `json:"ConnectionDisconnectSpan_u32"` 62 | AuthType int `json:"AuthType_u32"` 63 | Username string `json:"Username_str"` 64 | HashedPassword string `json:"HashedPassword_bin"` 65 | PlainPassword string `json:"PlainPassword_str"` 66 | ClientX string `json:"ClientX_bin"` 67 | ClientK string `json:"ClientK_bin"` 68 | CreateLinkPolicy 69 | } 70 | 71 | func newCreateLinkParams(hubNameEx, accountName string) *CreateLinkParams { 72 | return &CreateLinkParams{ 73 | HubNameEx: hubNameEx, 74 | AccountName: accountName, 75 | } 76 | } 77 | 78 | type CreateLinkPolicy struct { 79 | DHCPFilter bool `json:"policy:DHCPFilter_bool"` 80 | DHCPNoServer bool `json:"policy:DHCPNoServer_bool"` 81 | DHCPForce bool `json:"policy:DHCPForce_bool"` 82 | CheckMac bool `json:"SecPol_CheckMac_bool"` 83 | CheckIP bool `json:"SecPol_CheckIP_bool"` 84 | ArpDhcpOnly bool `json:"policy:ArpDhcpOnly_bool"` 85 | PrivacyFilter bool `json:"policy:PrivacyFilter_bool"` 86 | NoServer bool `json:"policy:NoServer_bool"` 87 | NoBroadcastLimiter bool `json:"policy:NoBroadcastLimiter_bool"` 88 | MaxMac int `json:"policy:MaxMac_u32"` 89 | MaxIP int `json:"policy:MaxIP_u32"` 90 | MaxUpload int `json:"policy:MaxUpload_u32"` 91 | MaxDownload int `json:"policy:MaxDownload_u32"` 92 | RSandRAFilter bool `json:"policy:RSandRAFilter_bool"` 93 | RAFilter bool `json:"SecPol_RAFilter_bool"` 94 | DHCPv6Filter bool `json:"policy:DHCPv6Filter_bool"` 95 | DHCPv6NoServer bool `json:"policy:DHCPv6NoServer_bool"` 96 | CheckIPv6 bool `json:"SecPol_CheckIPv6_bool"` 97 | NoServerV6 bool `json:"policy:NoServerV6_bool"` 98 | MaxIPv6 int `json:"policy:MaxIPv6_u32"` 99 | FilterIPv4 bool `json:"policy:FilterIPv4_bool"` 100 | FilterIPv6 bool `json:"policy:FilterIPv6_bool"` 101 | FilterNonIP bool `json:"policy:FilterNonIP_bool"` 102 | NoIPv6DefaultRouterInRA bool `json:"policy:NoIPv6DefaultRouterInRA_bool"` 103 | VLanId int `json:"policy:VLanId_u32"` 104 | Ver3 bool `json:"policy:Ver3_bool"` 105 | } 106 | 107 | func (pol *CreateLinkPolicy) Tags() []string { 108 | tmp := CreateLinkPolicy{} 109 | t := reflect.TypeOf(tmp) 110 | var tags []string 111 | for i := 0; i < t.NumField(); i++ { 112 | tag := t.Field(i).Tag.Get("json") 113 | tags = append(tags, tag) 114 | } 115 | return tags 116 | } 117 | 118 | func (p *CreateLinkParams) Tags() []string { 119 | tags := []string{ 120 | "HubName_Ex_str", 121 | "CheckServerCert_bool", 122 | "AccountName_utf", 123 | "Hostname_str", 124 | "Port_u32", 125 | "ProxyType_u32", 126 | "HubName_str", 127 | "MaxConnection_u32", 128 | "UseEncrypt_bool", 129 | "UseCompress_bool", 130 | "HalfConnection_bool", 131 | "AdditionalConnectionInterval_u32", 132 | "ConnectionDisconnectSpan_u32", 133 | "AuthType_u32", 134 | "Username_str", 135 | "HashedPassword_bin", 136 | "PlainPassword_str", 137 | "ClientX_bin", 138 | "ClientK_bin", 139 | } 140 | tags = append(tags, p.CreateLinkPolicy.Tags()...) 141 | return tags 142 | } 143 | -------------------------------------------------------------------------------- /methods/create_user.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | "reflect" 8 | "time" 9 | ) 10 | 11 | type CreateUser struct { 12 | pkg.Base 13 | Params *CreateUserParams `json:"params"` 14 | } 15 | 16 | func (g *CreateUser) Parameter() pkg.Params { 17 | return g.Params 18 | } 19 | 20 | func NewCreateUser(hub, name, realname, note string, expire *time.Time, auth int) *CreateUser { 21 | return &CreateUser{ 22 | Base: pkg.NewBase("CreateUser"), 23 | Params: newCreateUserParmas(hub, name, realname, note, expire, auth), 24 | } 25 | } 26 | 27 | func (g *CreateUser) Name() string { 28 | return g.Base.Name 29 | } 30 | 31 | func (g *CreateUser) GetId() int { 32 | return g.Id 33 | } 34 | 35 | func (g *CreateUser) SetId(id int) { 36 | g.Base.Id = id 37 | } 38 | 39 | func (g *CreateUser) Marshall() ([]byte, error) { 40 | data, err := json.Marshal(g) 41 | if err != nil { 42 | return nil, err 43 | } 44 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 45 | return res, nil 46 | } 47 | 48 | type CreateUserParams struct { 49 | HubName string `json:"HubName_str"` 50 | Name string `json:"Name_str"` 51 | Realname string `json:"Realname_utf"` 52 | Note string `json:"Note_utf"` 53 | ExpireTime *time.Time `json:"ExpireTime_dt"` 54 | AuthType int `json:"AuthType_u32"` 55 | Auth_Passoword string `json:"Auth_Password_str"` 56 | UserX string `json:"UserX_bin"` 57 | Serial string `json:"Serial_bin"` 58 | CommonName string `json:"CommonName_utf"` 59 | RadiusUsername string `json:"RadiusUsername_utf"` 60 | NtUsername string `json:"NtUsername_str"` 61 | UsePolicy bool `josn:"UsePolicy_bool"` 62 | CreateUserPolicy 63 | } 64 | 65 | func newCreateUserParmas(hub, name, realname, note string, expire *time.Time, auth int) *CreateUserParams { 66 | return &CreateUserParams{ 67 | HubName: hub, 68 | Name: name, 69 | Realname: realname, 70 | Note: note, 71 | ExpireTime: expire, 72 | AuthType: auth, 73 | } 74 | } 75 | 76 | type CreateUserPolicy struct { 77 | Access bool `json:"policy:Access_bool"` 78 | DHCPFilter bool `json:"policy:DHCPFilter_bool"` 79 | DHCPNoServer bool `json:"policy:DHCPNoServer_bool"` 80 | DHCPForce bool `json:"policy:DHCPForce_bool"` 81 | NoBridge bool `json:"policy:NoBridge_bool"` 82 | NoRouting bool `json:"policy:NoRouting_bool"` 83 | CheckMac bool `json:"policy:CheckMac_bool"` 84 | CheckIp bool `json:"policy:CheckIp_bool"` 85 | ArpDhcpOnly bool `json:"policy:ArpDhcpOnly_bool"` 86 | PrivacyFilter bool `json:"policy:PrivacyFilter_bool"` 87 | NoServer bool `json:"policy:NoServer_bool"` 88 | NoBroadcastLimiter bool `json:"policy:NoBroadcastLimiter_bool"` 89 | MonitorPort bool `json:"policy:MonitorPort_bool"` 90 | MaxConnection int `json:"policy:MaxConnection_u32"` 91 | TimeOut int `json:"policy:TimeOut_u32"` 92 | MaxMac int `json:"policy:MaxMac_u32"` 93 | MaxIp int `json:"policy:MaxIp_u32"` 94 | MaxUpload int `json:"MaxUpload_u32"` 95 | MaxDownload int `json:"MaxDownload_u32"` 96 | FixPassword bool `json:"policy:FixPassword_bool"` 97 | MultiLogins int `json:"policy:MultiLogins_u32"` 98 | NoQos bool `json:"policy:NoQos_bool"` 99 | RSandRAFilter bool `json:"policy:RSandRAFilter_bool"` 100 | RAFilter bool `json:"policy:RAFilter_bool"` 101 | DHCPv6Filter bool `json:"policy:DHCPv6Filter_bool"` 102 | DHCPv6NoServer bool `json:"policy:DHCPv6NoServer_bool"` 103 | NoRoutingV6 bool `json:"policy:NoRoutingV6_bool"` 104 | CheckIPv6 bool `json:"policy:CheckIPv6_bool"` 105 | NoServerV6 bool `json:"policy:NoServerV6_bool"` 106 | MaxIPv6 int `json:"policy:MaxIPv6_u32"` 107 | NoSavePassword bool `json:"policy:NoSavePassword_bool"` 108 | AutoDisconnect int `json:"policy:AutoDisconnect_bool"` 109 | FilterIPv4 bool `json:"policy:FilterIPv4_bool"` 110 | FilterIPv6 bool `json:"policy:FilterIPv6_bool"` 111 | FilterNonIP bool `json:"policy:FilterNonIP_bool"` 112 | NoIPv6DefaultRouterInRA bool `json:"policy:NoIPv6DefaultRouterInRA_bool"` 113 | NoIPv6DefaultRouterInRAWhenIPv6 bool `json:"policy:NoIPv6DefaultRouterInRAWhenIPv6_bool"` 114 | VLanId int `json:"policy:VLanId_u32"` 115 | Ver3 bool `json:"policy:policy:Ver3_bool"` 116 | } 117 | 118 | func (pol *CreateUserPolicy) Tags() []string { 119 | tmp := CreateUserPolicy{} 120 | t := reflect.TypeOf(tmp) 121 | var tags []string 122 | for i := 0; i < t.NumField(); i++ { 123 | tag := t.Field(i).Tag.Get("json") 124 | tags = append(tags, tag) 125 | } 126 | return tags 127 | } 128 | 129 | func (p *CreateUserParams) Tags() []string { 130 | tags := []string{ 131 | "HubName_str", 132 | "Name_str", 133 | "Realname_utf", 134 | "Note_utf", 135 | "ExpireTime_dt", 136 | "AuthType_u32", 137 | "Auth_Password_str", 138 | "UserX_bin", 139 | "Serial_bin", 140 | "CommonName_utf", 141 | "RadiusUsername_utf", 142 | "NtUsername_utf", 143 | "UsePolicy_bool", 144 | } 145 | tags = append(tags, p.CreateUserPolicy.Tags()...) 146 | return tags 147 | } 148 | -------------------------------------------------------------------------------- /methods/set_user.go: -------------------------------------------------------------------------------- 1 | package methods 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "github.com/terassyi/go-softether-api/pkg" 7 | "reflect" 8 | "time" 9 | ) 10 | 11 | type SetUSer struct { 12 | pkg.Base 13 | Params *SetUSerParams `json:"params"` 14 | } 15 | 16 | func (g *SetUSer) Parameter() pkg.Params { 17 | return g.Params 18 | } 19 | 20 | func NewSetUSer(hub, name, realname, group, note string, expire *time.Time, auth int) *SetUSer { 21 | return &SetUSer{ 22 | Base: pkg.NewBase("SetUSer"), 23 | Params: newSetUSerParmas(hub, name, realname, group, note, expire, auth), 24 | } 25 | } 26 | 27 | func (g *SetUSer) Name() string { 28 | return g.Base.Name 29 | } 30 | 31 | func (g *SetUSer) GetId() int { 32 | return g.Id 33 | } 34 | 35 | func (g *SetUSer) SetId(id int) { 36 | g.Base.Id = id 37 | } 38 | 39 | func (g *SetUSer) Marshall() ([]byte, error) { 40 | data, err := json.Marshal(g) 41 | if err != nil { 42 | return nil, err 43 | } 44 | res := bytes.Replace(data, []byte("null"), []byte("{}"), -1) 45 | return res, nil 46 | } 47 | 48 | type SetUSerParams struct { 49 | HubName string `json:"HubName_str"` 50 | Name string `json:"Name_str"` 51 | GroupName string `json:"GroupName_str"` 52 | Realname string `json:"Realname_utf"` 53 | Note string `json:"Note_utf"` 54 | ExpireTime *time.Time `json:"ExpireTime_dt"` 55 | AuthType int `json:"AuthType_u32"` 56 | Auth_Passoword string `json:"Auth_Password_str"` 57 | UserX string `json:"UserX_bin"` 58 | Serial string `json:"Serial_bin"` 59 | CommonName string `json:"CommonName_utf"` 60 | RadiusUsername string `json:"RadiusUsername_utf"` 61 | NtUsername string `json:"NtUsername_str"` 62 | UsePolicy bool `josn:"UsePolicy_bool"` 63 | SetUSerPolicy 64 | } 65 | 66 | func newSetUSerParmas(hub, name, realname, group, note string, expire *time.Time, auth int) *SetUSerParams { 67 | return &SetUSerParams{ 68 | HubName: hub, 69 | Name: name, 70 | Realname: realname, 71 | GroupName: group, 72 | Note: note, 73 | ExpireTime: expire, 74 | AuthType: auth, 75 | } 76 | } 77 | 78 | type SetUSerPolicy struct { 79 | Access bool `json:"policy:Access_bool"` 80 | DHCPFilter bool `json:"policy:DHCPFilter_bool"` 81 | DHCPNoServer bool `json:"policy:DHCPNoServer_bool"` 82 | DHCPForce bool `json:"policy:DHCPForce_bool"` 83 | NoBridge bool `json:"policy:NoBridge_bool"` 84 | NoRouting bool `json:"policy:NoRouting_bool"` 85 | CheckMac bool `json:"policy:CheckMac_bool"` 86 | CheckIp bool `json:"policy:CheckIp_bool"` 87 | ArpDhcpOnly bool `json:"policy:ArpDhcpOnly_bool"` 88 | PrivacyFilter bool `json:"policy:PrivacyFilter_bool"` 89 | NoServer bool `json:"policy:NoServer_bool"` 90 | NoBroadcastLimiter bool `json:"policy:NoBroadcastLimiter_bool"` 91 | MonitorPort bool `json:"policy:MonitorPort_bool"` 92 | MaxConnection int `json:"policy:MaxConnection_u32"` 93 | TimeOut int `json:"policy:TimeOut_u32"` 94 | MaxMac int `json:"policy:MaxMac_u32"` 95 | MaxIp int `json:"policy:MaxIp_u32"` 96 | MaxUpload int `json:"MaxUpload_u32"` 97 | MaxDownload int `json:"MaxDownload_u32"` 98 | FixPassword bool `json:"policy:FixPassword_bool"` 99 | MultiLogins int `json:"policy:MultiLogins_u32"` 100 | NoQos bool `json:"policy:NoQos_bool"` 101 | RSandRAFilter bool `json:"policy:RSandRAFilter_bool"` 102 | RAFilter bool `json:"policy:RAFilter_bool"` 103 | DHCPv6Filter bool `json:"policy:DHCPv6Filter_bool"` 104 | DHCPv6NoServer bool `json:"policy:DHCPv6NoServer_bool"` 105 | NoRoutingV6 bool `json:"policy:NoRoutingV6_bool"` 106 | CheckIPv6 bool `json:"policy:CheckIPv6_bool"` 107 | NoServerV6 bool `json:"policy:NoServerV6_bool"` 108 | MaxIPv6 int `json:"policy:MaxIPv6_u32"` 109 | NoSavePassword bool `json:"policy:NoSavePassword_bool"` 110 | AutoDisconnect int `json:"policy:AutoDisconnect_bool"` 111 | FilterIPv4 bool `json:"policy:FilterIPv4_bool"` 112 | FilterIPv6 bool `json:"policy:FilterIPv6_bool"` 113 | FilterNonIP bool `json:"policy:FilterNonIP_bool"` 114 | NoIPv6DefaultRouterInRA bool `json:"policy:NoIPv6DefaultRouterInRA_bool"` 115 | NoIPv6DefaultRouterInRAWhenIPv6 bool `json:"policy:NoIPv6DefaultRouterInRAWhenIPv6_bool"` 116 | VLanId int `json:"policy:VLanId_u32"` 117 | Ver3 bool `json:"policy:policy:Ver3_bool"` 118 | } 119 | 120 | func (pol *SetUSerPolicy) Tags() []string { 121 | tmp := SetUSerPolicy{} 122 | t := reflect.TypeOf(tmp) 123 | var tags []string 124 | for i := 0; i < t.NumField(); i++ { 125 | tag := t.Field(i).Tag.Get("json") 126 | tags = append(tags, tag) 127 | } 128 | return tags 129 | } 130 | 131 | func (p *SetUSerParams) Tags() []string { 132 | tags := []string{ 133 | "HubName_str", 134 | "Name_str", 135 | "Realname_utf", 136 | "Note_utf", 137 | "ExpireTime_dt", 138 | "AuthType_u32", 139 | "Auth_Password_str", 140 | "UserX_bin", 141 | "Serial_bin", 142 | "CommonName_utf", 143 | "RadiusUsername_utf", 144 | "NtUsername_utf", 145 | "UsePolicy_bool", 146 | } 147 | tags = append(tags, p.SetUSerPolicy.Tags()...) 148 | return tags 149 | } 150 | --------------------------------------------------------------------------------