add action items menu

This commit is contained in:
juancwu 2026-01-21 21:27:08 +00:00
commit 4266bfbfc2
5 changed files with 172 additions and 20 deletions

View file

@ -25,3 +25,49 @@ func New(apiKey, secretKey string) *Client {
},
}
}
func (c *Client) Ping() (*PingResponse, error) {
reqBody := PingRequest{
BaseRequest: BaseRequest{
APIKey: c.APIKey,
SecretAPIKey: c.SecretAPIKey,
},
}
var resp PingResponse
err := c.post("/ping", reqBody, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
func (c *Client) post(endpoint string, body interface{}, target interface{}) error {
jsonBody, err := json.Marshal(body)
if err != nil {
return fmt.Errorf("failed to marshal request body: %w", err)
}
req, err := http.NewRequest("POST", BaseURL+endpoint, bytes.NewBuffer(jsonBody))
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
res, err := c.HTTPClient.Do(req)
if err != nil {
return fmt.Errorf("request failed: %w", err)
}
defer res.Body.Close()
if res.StatusCode >= 400 {
return fmt.Errorf("API returned error status: %d", res.StatusCode)
}
if err := json.NewDecoder(res.Body).Decode(target); err != nil {
return fmt.Errorf("failed to decode response: %w", err)
}
return nil
}

View file

@ -0,0 +1,24 @@
package porkbun
// BaseRequest contains the authentication fields required for most Porkbun API calls.
type BaseRequest struct {
APIKey string `json:"apikey"`
SecretAPIKey string `json:"secretapikey"`
}
// BaseResponse contains the common fields returned by the Porkbun API.
type BaseResponse struct {
Status string `json:"status"`
Message string `json:"message,omitempty"`
}
// PingRequest is used to verify credentials.
type PingRequest struct {
BaseRequest
}
// PingResponse is the response from the ping endpoint.
type PingResponse struct {
BaseResponse
YourIP string `json:"yourIp"`
}