fix get url arguments passing

chore: update gitignore
chore: rename some structures
feat: support sdk init
This commit is contained in:
XingfenD
2026-08-03 15:21:01 +08:00
parent 2605bf350c
commit 5604a3f2f0
7 changed files with 57 additions and 12 deletions
+9 -1
View File
@@ -32,4 +32,12 @@ go.work.sum
.vscode/ .vscode/
.opencode/ .opencode/
docs/superpowers/ docs/superpowers/
# AGENTS
reasonix.toml
opencode.json
.claude/
.opencode/
.hermers/
+8 -4
View File
@@ -8,26 +8,30 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
) )
type Client struct { type RyClient struct {
APIKey string APIKey string
client *resty.Client client *resty.Client
} }
func New(apiKey string) *Client { func NewRyClient(apiKey string) *RyClient {
c := resty.New() c := resty.New()
c.SetBaseURL(constant.BaseURL) c.SetBaseURL(constant.BaseURL)
c.SetHeader("x-api-key", apiKey) c.SetHeader("x-api-key", apiKey)
c.SetHeader("User-Agent", "github.com/XingfenD/rainyun_api_go_sdk/"+constant.RainyunSdkVersion) c.SetHeader("User-Agent", "github.com/XingfenD/rainyun_api_go_sdk/"+constant.RainyunSdkVersion)
c.SetHeader("Accept", "application/json") c.SetHeader("Accept", "application/json")
return &Client{ return &RyClient{
APIKey: apiKey, APIKey: apiKey,
client: c, 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() req := c.client.R()
if querys != nil {
req.SetQueryParams(querys)
}
if body != nil { if body != nil {
req.SetBody(body) req.SetBody(body)
} }
+2 -2
View File
@@ -3,9 +3,9 @@ package public
import "github.com/XingfenD/rainyun_api_go_sdk/apis" import "github.com/XingfenD/rainyun_api_go_sdk/apis"
type PublicService struct { 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} return &PublicService{client: c}
} }
+1 -1
View File
@@ -29,6 +29,6 @@ type AppConfigValue struct {
func (s *PublicService) GetAppConfig() (*GetAppConfigResponse, error) { func (s *PublicService) GetAppConfig() (*GetAppConfigResponse, error) {
path := "/app_config" path := "/app_config"
var resp GetAppConfigResponse 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 return &resp, err
} }
+1 -1
View File
@@ -24,7 +24,7 @@ func (s *PublicService) GetNews() (*GetNewsResponse, error) {
path := "/news" path := "/news"
var resp GetNewsResponse 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 return &resp, err
} }
+20 -3
View File
@@ -3,6 +3,7 @@ package public
import ( import (
"github.com/XingfenD/rainyun_api_go_sdk/apis/common" "github.com/XingfenD/rainyun_api_go_sdk/apis/common"
"github.com/XingfenD/rainyun_api_go_sdk/constant" "github.com/XingfenD/rainyun_api_go_sdk/constant"
"github.com/bytedance/sonic"
) )
// https://api.rainyun.com/#/paths/status/get // https://api.rainyun.com/#/paths/status/get
@@ -34,11 +35,27 @@ type NodeStatusRecordItem struct {
Data string `json:"Data"` Data string `json:"Data"`
} }
// TODO func (req *GetStatusRequest) BuildQueryMap() (map[string]string, error) {
func (s *PublicService) GetStatus() (*GetStatusResponse, 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" path := "/status"
var resp GetStatusResponse 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 return &resp, err
} }
+16
View File
@@ -1 +1,17 @@
package sdk 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),
}
}