mirror of
https://github.com/fumiama/tienyik.git
synced 2026-06-11 10:30:24 +08:00
feat: add more apis
This commit is contained in:
32
api/cdserv/client.go
Normal file
32
api/cdserv/client.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cdserv
|
||||
|
||||
import (
|
||||
"github.com/fumiama/tienyik/hcli"
|
||||
"github.com/fumiama/tienyik/internal/hson"
|
||||
"github.com/fumiama/tienyik/internal/textio"
|
||||
)
|
||||
|
||||
type GlobalSwitches struct {
|
||||
BodyMsgEType []string `json:"bodyMsgEType"`
|
||||
PasswordRulesEnable bool `json:"passwordRulesEnable"`
|
||||
}
|
||||
|
||||
type ResponseGetServData struct {
|
||||
GlobalSwitches GlobalSwitches `json:"globalSwitches"`
|
||||
ServerNodeId string `json:"serverNodeId"`
|
||||
Timestamp int64 `json:"timestamp"`
|
||||
NetAccessType int `json:"netAccessType"`
|
||||
}
|
||||
|
||||
func (r *ResponseGetServData) SetClient(cli *hcli.Client) {
|
||||
cli.Servernode = r.ServerNodeId
|
||||
}
|
||||
|
||||
func GetServData() (*ResponseGetServData, error) {
|
||||
resp, err := hcli.NoClient.Get(textio.API())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return hson.Unmarshal[*ResponseGetServData](nil, resp.Body)
|
||||
}
|
||||
14
api/cdserv/client_test.go
Normal file
14
api/cdserv/client_test.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package cdserv
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetServData(t *testing.T) {
|
||||
r, err := GetServData()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(r)
|
||||
if len(r.GlobalSwitches.BodyMsgEType) == 0 {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user