release: WRNexusJS 0.8.0
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
package wrnexussdk
|
||||
|
||||
import ("bytes"; "encoding/json"; "fmt"; "net/http")
|
||||
type Client struct { BaseURL string; HTTP *http.Client }
|
||||
func (c *Client) Request(method, path string, body any) (map[string]any, error) { data,_:=json.Marshal(body); req,_:=http.NewRequest(method,c.BaseURL+path,bytes.NewReader(data)); req.Header.Set("content-type","application/json"); client:=c.HTTP;if client==nil{client=http.DefaultClient};res,err:=client.Do(req);if err!=nil{return nil,err};defer res.Body.Close();if res.StatusCode>=400{return nil,fmt.Errorf("API status %d",res.StatusCode)};var out map[string]any;err=json.NewDecoder(res.Body).Decode(&out);return out,err }
|
||||
Reference in New Issue
Block a user