update basic frame

This commit is contained in:
2026-08-02 22:05:19 +08:00
parent 73aad6b718
commit 525e0e7412
15 changed files with 213 additions and 4 deletions
+56
View File
@@ -0,0 +1,56 @@
package apis
import (
"fmt"
"github.com/XingfenD/rainyun_api_go_sdk/constant"
"github.com/bytedance/sonic"
"github.com/go-resty/resty/v2"
)
type Client struct {
APIKey string
client *resty.Client
}
func New(apiKey string) *Client {
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{
APIKey: apiKey,
client: c,
}
}
func (c *Client) Do(method constant.HTTPMethod, endpoint string, body, result any) error {
req := c.client.R()
if body != nil {
req.SetBody(body)
}
if result != nil {
req.SetResult(result)
}
resp, err := req.Execute(string(method), endpoint)
if err != nil {
return err
}
if resp.StatusCode() != 200 {
var baseResp struct {
Code int `json:"code"`
Message string `json:"message"`
}
if err := sonic.Unmarshal(resp.Body(), &baseResp); err != nil {
return err
}
return fmt.Errorf(fmt.Sprint(baseResp.Code))
}
return nil
}
+11
View File
@@ -0,0 +1,11 @@
package public
import "github.com/XingfenD/rainyun_api_go_sdk/apis"
type Service struct {
client *apis.Client
}
func NewService(c *apis.Client) *Service {
return &Service{client: c}
}
+34
View File
@@ -0,0 +1,34 @@
package public
import "github.com/XingfenD/rainyun_api_go_sdk/constant"
type AppConfigItemResponse struct {
Code int `json:"code"`
Data []AppConfigItem `json:"data"`
Messages []string `json:"messages,omitempty"`
Msg string `json:"msg,omitempty"`
}
type AppConfigItem struct {
AgentID int `json:"agent_id"`
Type string `json:"type"`
Value []AppConfigValue `json:"value"`
}
type AppConfigValue struct {
SenderID int `json:"sender_id"`
Content string `json:"content"`
Title string `json:"title"`
Name string `json:"name"`
Order int `json:"order"`
Page string `json:"page"`
VgtID int `json:"vgt_id"`
OriginalIndex int `json:"originalIndex"`
}
func (s *Service) GetAppConfig() (*AppConfigItemResponse, error) {
path := "/app_config"
var resp AppConfigItemResponse
err := s.client.Do(constant.HTTPMethod_GET, path, nil, &resp)
return &resp, err
}
+1
View File
@@ -0,0 +1 @@
package public