From 5604a3f2f0daa7faceac1d72e62a645399ef11af Mon Sep 17 00:00:00 2001 From: XingfenD Date: Mon, 3 Aug 2026 15:20:41 +0800 Subject: [PATCH] fix get url arguments passing chore: update gitignore chore: rename some structures feat: support sdk init --- .gitignore | 10 +++++++++- apis/client.go | 12 ++++++++---- apis/public/client.go | 4 ++-- apis/public/get_app_config.go | 2 +- apis/public/get_news.go | 2 +- apis/public/get_status.go | 23 ++++++++++++++++++++--- sdk/sdk.go | 16 ++++++++++++++++ 7 files changed, 57 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index e3a2ac5..5544937 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,12 @@ go.work.sum .vscode/ .opencode/ -docs/superpowers/ \ No newline at end of file +docs/superpowers/ + +# AGENTS + +reasonix.toml +opencode.json +.claude/ +.opencode/ +.hermers/ \ No newline at end of file diff --git a/apis/client.go b/apis/client.go index 87e2fb5..150faff 100644 --- a/apis/client.go +++ b/apis/client.go @@ -8,26 +8,30 @@ import ( "github.com/go-resty/resty/v2" ) -type Client struct { +type RyClient struct { APIKey string client *resty.Client } -func New(apiKey string) *Client { +func NewRyClient(apiKey string) *RyClient { c := resty.New() c.SetBaseURL(constant.BaseURL) c.SetHeader("x-api-key", apiKey) c.SetHeader("User-Agent", "github.com/XingfenD/rainyun_api_go_sdk/"+constant.RainyunSdkVersion) c.SetHeader("Accept", "application/json") - return &Client{ + return &RyClient{ APIKey: apiKey, client: c, } } -func (c *Client) Do(method constant.HTTPMethod, endpoint string, body, result any) error { +func (c *RyClient) Do(method constant.HTTPMethod, endpoint string, querys map[string]string, body, result any) error { req := c.client.R() + if querys != nil { + req.SetQueryParams(querys) + } + if body != nil { req.SetBody(body) } diff --git a/apis/public/client.go b/apis/public/client.go index 0bfe07d..58c254d 100644 --- a/apis/public/client.go +++ b/apis/public/client.go @@ -3,9 +3,9 @@ package public import "github.com/XingfenD/rainyun_api_go_sdk/apis" type PublicService struct { - client *apis.Client + client *apis.RyClient } -func NewPublicService(c *apis.Client) *PublicService { +func NewPublicService(c *apis.RyClient) *PublicService { return &PublicService{client: c} } diff --git a/apis/public/get_app_config.go b/apis/public/get_app_config.go index aad4346..d9ee7dc 100644 --- a/apis/public/get_app_config.go +++ b/apis/public/get_app_config.go @@ -29,6 +29,6 @@ type AppConfigValue struct { func (s *PublicService) GetAppConfig() (*GetAppConfigResponse, error) { path := "/app_config" var resp GetAppConfigResponse - err := s.client.Do(constant.HTTPMethod_GET, path, nil, &resp) + err := s.client.Do(constant.HTTPMethod_GET, path, nil, nil, &resp) return &resp, err } diff --git a/apis/public/get_news.go b/apis/public/get_news.go index c86aca1..b7deedb 100644 --- a/apis/public/get_news.go +++ b/apis/public/get_news.go @@ -24,7 +24,7 @@ func (s *PublicService) GetNews() (*GetNewsResponse, error) { path := "/news" var resp GetNewsResponse - err := s.client.Do(constant.HTTPMethod_GET, path, nil, &resp) + err := s.client.Do(constant.HTTPMethod_GET, path, nil, nil, &resp) return &resp, err } diff --git a/apis/public/get_status.go b/apis/public/get_status.go index 008f300..f4c0b60 100644 --- a/apis/public/get_status.go +++ b/apis/public/get_status.go @@ -3,6 +3,7 @@ package public import ( "github.com/XingfenD/rainyun_api_go_sdk/apis/common" "github.com/XingfenD/rainyun_api_go_sdk/constant" + "github.com/bytedance/sonic" ) // https://api.rainyun.com/#/paths/status/get @@ -34,11 +35,27 @@ type NodeStatusRecordItem struct { Data string `json:"Data"` } -// TODO -func (s *PublicService) GetStatus() (*GetStatusResponse, error) { +func (req *GetStatusRequest) BuildQueryMap() (map[string]string, error) { + rst := make(map[string]string, 1) + optionString, err := sonic.Marshal(req.Options) + if err != nil { + return nil, err + } + + rst["options"] = string(optionString) + + return rst, nil +} + +func (s *PublicService) GetStatus(req *GetStatusRequest) (*GetStatusResponse, error) { path := "/status" var resp GetStatusResponse - err := s.client.Do(constant.HTTPMethod_GET, path, nil, &resp) + + querys, err := req.BuildQueryMap() + if err != nil { + return nil, err + } + err = s.client.Do(constant.HTTPMethod_GET, path, querys, nil, &resp) return &resp, err } diff --git a/sdk/sdk.go b/sdk/sdk.go index 0919fd1..7b3d405 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -1 +1,17 @@ package sdk + +import ( + "github.com/XingfenD/rainyun_api_go_sdk/apis" + "github.com/XingfenD/rainyun_api_go_sdk/apis/public" +) + +type RainyunSDK struct { + public.PublicService +} + +func New(apiKey string) *RainyunSDK { + c := apis.NewRyClient(apiKey) + return &RainyunSDK{ + PublicService: *public.NewPublicService(c), + } +}