opentaobao

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 15 Imported by: 0

README

taobaogo

淘宝Api、淘宝开放平台Api请求基础SDK

淘宝API

sign算法

淘宝Session

Example 🌰

package main

import (
	"context"
	"log"
	"os"

	"github.com/nilorg/go-opentaobao/v2"
)

func main() {
	client := opentaobao.NewClient(
		opentaobao.WithAppKey(os.Getenv("APP_KEY")),
		opentaobao.WithAppSecret(os.Getenv("APP_SECRET")),
	)
	ctx := context.Background()
	// EXP: 使用session
	// ctx = opentaobao.NewSessionContext(ctx, "session")
	result, err := client.Execute(ctx, "taobao.tbk.dg.material.optional", opentaobao.Parameter{
		"q":         "鸿星尔克男鞋板鞋",
		"adzone_id": os.Getenv("ADZONE_ID"),
		"platform":  "2",
	})

	if err != nil {
		log.Printf("execute error:%s\n", err)
		return
	}
	log.Printf("result:%s\n", result.String())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTypeIsNil   = errors.New("类型为Nil")
	ErrTypeUnknown = errors.New("未处理到的数据类型")
)

Functions

func FromSessionContext

func FromSessionContext(ctx context.Context) (session string, ok bool)

func NewSessionContext

func NewSessionContext(parent context.Context, session string) context.Context

func RespDecode

func RespDecode(httpResp *http.Response, v any) error

func Sign

func Sign(params Parameter, appSecret string) string

获取签名

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) *Client

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, method string, param Parameter) (res gjson.Result, err error)

Execute 执行API接口

type Error

type Error struct {
	Code    int    `json:"code" swaggo:"true,错误码"`
	Message string `json:"message" swaggo:"true,错误信息"`
}

Error HTTP响应错误项

type Option

type Option func(*Options)

Option 为可选参数赋值的函数

func WithAppKey

func WithAppKey(appKey string) Option

WithAppKey 设置应用Key

func WithAppSecret

func WithAppSecret(appSecret string) Option

WithAppSecret 设置秘密

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient 设置HTTP客户端

func WithJSONSimplify

func WithJSONSimplify(jsonSimplify bool) Option

WithJSONSimplify 设置是否开启JSON返回值的简化模式

func WithRouter

func WithRouter(router string) Option

WithRouter 设置环境请求地址

type Options

type Options struct {
	Router       string // 环境请求地址
	AppKey       string // 应用Key
	AppSecret    string // 秘密
	JSONSimplify bool   // 是否开启JSON返回值的简化模式
	// contains filtered or unexported fields
}

Options 可选参数列表

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions 创建可选参数

type Parameter

type Parameter map[string]any

Parameter 参数

type Response

type Response struct {
	Err  Error `json:"error" swaggo:"true,错误项"`
	Data any   `json:"data"`
}

func (*Response) Error

func (e *Response) Error() error

func (*Response) IsError

func (e *Response) IsError() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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