Skip to content

Latest commit

 

History

History
92 lines (86 loc) · 2.27 KB

README.md

File metadata and controls

92 lines (86 loc) · 2.27 KB

Go SDK的用法说明

安装


go get github.com/assetcloud/zcy-sdk-go

使用

Get调用方法:

    import (
    	asset "github.com/assetcloud/zcy-sdk-go"
    )

    request := &asset.AssetCloudRequest{
        Url:        "",
        Key:        "",
        Secret:     "",
        Body:       "",
        HttpMethod: asset.GET,
    }
    response := asset.Send(request)
    respBytes, _ := json.Marshal(response)
    println(string(respBytes))

Post调用方法:

    import (
    	"encoding/json"
    	asset "github.com/assetcloud/zcy-sdk-go"
    )

    bodyMap := make(map[string]interface{})
    bodyMap["key1"] = "val1"
    bodyBytes, _ := json.Marshal(bodyMap)
    postRequest := &asset.AssetCloudRequest{
        Url:        "",
        Key:        "",
        Secret:     "",
        Body:       string(bodyBytes),
        HttpMethod: asset.POST,
    }
    postResponse := asset.Send(postRequest)
    postRespBytes, _ := json.Marshal(postResponse)
    println(string(postRespBytes))

DELETE调用方法:

    import (
        asset "github.com/assetcloud/zcy-sdk-go"
    )

    request := &asset.AssetCloudRequest{
        Url:        "",
        Key:        "",
        Secret:     "",
        Body:       "",
        HttpMethod: asset.DELETE,
    }
    response := asset.Send(request)
    respBytes, _ := json.Marshal(response)
    println(string(respBytes))

PUT调用方法:

    import (
    	"encoding/json"
    	asset "github.com/assetcloud/zcy-sdk-go"
    )

    bodyMap := make(map[string]interface{})
    bodyMap["key1"] = "val1"
    bodyBytes, _ := json.Marshal(bodyMap)
    postRequest := &asset.AssetCloudRequest{
        Url:        "",
        Key:        "",
        Secret:     "",
        Body:       string(bodyBytes),
        HttpMethod: asset.PUT,
    }
    postResponse := asset.Send(postRequest)
    postRespBytes, _ := json.Marshal(postResponse)
    println(string(postRespBytes))

返回结果为AssetCloudResponse:

字段 类型 说明
code int 状态码
success bool 是否成功
data T 承载数据
msg string 返回消息