csb

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

csb

阿里专有云csb sdk

仅支持http调用

根据阿里云官方sdk修改,支持contextgo module,官方sdk不支持

使用方法

package cron

import (
	"context"
	"fmt"

	"github.com/fnoopv/csb"
)

type Result struct {
	Data []struct {
		UserID          string `json:"USER_ID"`
		Mobile          string `json:"MOBILE"`
		Email           string `json:"EMAIL,omitempty"`
    }
	DataSize    int    `json:"dataSize"`
	Total       int    `json:"total"`
	ResultCode  int    `json:"resultCode"`
	ResultMsg   string `json:"resultMsg"`
	HasNextPage bool   `json:"hasNextPage"`
}

func SyncAvicUser() {
	c := csb.NewCSBClient("http://dadsa.com:8888/CSB", "dasdsa", "dadadadas=")
	c.SetApiName("users")
	c.SetApiMethod("get")
	c.SetApiVersion("1.0.0")
	c.SetContentType("application/json;charset=utf-8")

    // 添加query参数
	queryParam := make(map[string]string)
	queryParam["startTime"] = "0"
	c.SetQueryParam(queryParam)
    // 添加请求头
	headers := make(map[string]string)
	headers["appKey"] = "dasdadasd"
	c.SetHeaders(headers)

	result := Result{}
	err := c.Do(context.Background(), &result)
	if err != nil {
		fmt.Printf("request error: %s\n", err)
		return
	}
    fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSBClient

type CSBClient struct {
	ApiName     string            // 接口名称
	ApiMethod   string            // 接口请求方法
	ApiVersion  string            // 接口版本
	ContentType string            // 请求的content-type
	Headers     map[string]string // 请求头
	QueryParam  map[string]string // query参数
	FormParam   map[string]string // 表单数据
	Body        []byte            // 请求体,文件、表单、JSON等
	// contains filtered or unexported fields
}

CSBClient CSBClient

func NewCSBClient

func NewCSBClient(url, accessKey, secretKey string) *CSBClient

NewCSBClient 返回新的CSB客户端

func (*CSBClient) Do

func (c *CSBClient) Do(ctx context.Context, result interface{}) (*req.Response, error)

Do 执行请求

func (*CSBClient) SetApiMethod

func (c *CSBClient) SetApiMethod(apiMethod string) *CSBClient

SetApiMethod 设置请求接口的方法,只支持get或post

func (*CSBClient) SetApiName

func (c *CSBClient) SetApiName(apiName string) *CSBClient

SetApiName 设置请求接口的名称

func (*CSBClient) SetApiVersion

func (c *CSBClient) SetApiVersion(apiVersion string) *CSBClient

SetApiVersion 设置请求接口的版本

func (*CSBClient) SetBody

func (c *CSBClient) SetBody(body []byte) *CSBClient

SetBody 设置请求体

func (*CSBClient) SetContentType

func (c *CSBClient) SetContentType(contentType string) *CSBClient

SetContentType 设置请求content-type

func (*CSBClient) SetFormParam

func (c *CSBClient) SetFormParam(formParam map[string]string) *CSBClient

SetFormParam 设置表单数据

func (*CSBClient) SetHeaders

func (c *CSBClient) SetHeaders(headers map[string]string) *CSBClient

SetHeaders 设置请求头

func (*CSBClient) SetQueryParam

func (c *CSBClient) SetQueryParam(queryParam map[string]string) *CSBClient

SetQueryParam 设置query参数对

Jump to

Keyboard shortcuts

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