open_api_client_sdk_go

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 10 Imported by: 0

README

open-api-client-sdk-go

open API invoke client for Go

quickstart

  1. install
go get -u https://github.com/code-elastic/open-api-client-sdk-go
  1. use case
func TestInvoke(c *gin.Context) {
	//
	body, err := c.GetRawData()
	
	var interfaceInfo model.InterfaceInfo
	// TODO 给 interfaceInfo 赋值
	info, err := json.Marshal(&interfaceInfo)
	
	client, err := client.NewClient(body, info)
	if err != nil {
		c.JSON(http.StatusForbidden, utils.ResponseError(utils.ParamsError, "调用失败"))
		return
	}
	response := client.DoRequest()
	var res utils.Response
	err = json.Unmarshal(response, &res)
	if err != nil {
		fmt.Println("Unmarshal Error", err.Error())
		return
	}
	if res.Code != 0 {
		c.JSON(http.StatusForbidden, res)
		return
	}
	c.JSON(http.StatusOK, utils.ResponseOK(res.Data))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SerializeToJSON

func SerializeToJSON(data interface{}) (string, error)

SerializeToJSON 将任何数据类型转换为 JSON 格式的字符串。

Types

type Client added in v0.2.0

type Client struct {
	Header        model.Header        // Header 封装了用于API请求的头信息,如访问密钥、签名等
	InterfaceInfo model.InterfaceInfo // InterfaceInfo 包含特定API接口的相关信息,如URL、方法等
}

func NewClient added in v0.2.0

func NewClient(body, info []byte) (*Client, error)

func (*Client) DoRequest added in v0.2.0

func (c *Client) DoRequest() []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL