fix get url arguments passing
chore: update gitignore chore: rename some structures feat: support sdk init
This commit is contained in:
@@ -33,3 +33,11 @@ go.work.sum
|
||||
.opencode/
|
||||
|
||||
docs/superpowers/
|
||||
|
||||
# AGENTS
|
||||
|
||||
reasonix.toml
|
||||
opencode.json
|
||||
.claude/
|
||||
.opencode/
|
||||
.hermers/
|
||||
+8
-4
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+16
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user