http

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0, MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultHttpUrl = "https://openapi.longportapp.com"

DefaultHttpUrl

View Source
const DefaultTimeout = 15 * time.Second

DefaultTimeout

Variables

This section is empty.

Functions

func EncryptPassword

func EncryptPassword(raw, timestamp string) (encrypted string, err error)

EncryptPassword use to encrypt password Use aes with cbc mode to encrypt password 1. use md5(timestamp) as secret key for md5 have fixed length 2. use key[:16] is cbc iv 3. md5(raw_password) as plain content 4. padding plain content 5. encrypt

func NewError

func NewError(httpStatus int, resp *apiResponse) error

Types

type ApiError

type ApiError struct {
	HttpStatus int
	Code       int
	Message    string
}

func (*ApiError) Error

func (ae *ApiError) Error() string

type Client

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

Client is a http client to access Longbridge REST OpenAPI

func New

func New(opt ...Option) (*Client, error)

New create http client to call Longbridge REST OpenAPI

func NewFromCfg

func NewFromCfg(c *config.Config) (*Client, error)

NewFromCfg init longbridge http client from *config.Config

func (*Client) Call

func (c *Client) Call(ctx context.Context, method, path string, queryParams interface{}, body interface{}, resp interface{}, ropts ...RequestOption) (err error)

Call will send request with signature to http server

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, queryParams interface{}, resp interface{}, ropts ...RequestOption) error

Delete sends Delete request with queryParams

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, queryParams url.Values, resp interface{}, ropts ...RequestOption) error

Get sends Get request with queryParams

func (*Client) GetOTP

func (c *Client) GetOTP(ctx context.Context, ropts ...RequestOption) (string, error)

GetOTP to get one time password Reference: https://open.longportapp.com/en/docs/socket-token-api

func (*Client) GetOTPV2

func (c *Client) GetOTPV2(ctx context.Context, ropts ...RequestOption) (string, error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}, resp interface{}, ropts ...RequestOption) error

Post sends Post request with json body

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}, resp interface{}, ropts ...RequestOption) error

Put sends Put request with json body

type Option

type Option func(*Options)

Option for http client

func WithAccessToken

func WithAccessToken(accessToken string) Option

WithAccessToken to set access token

func WithAppKey

func WithAppKey(appKey string) Option

WithAppKey to set app key

func WithAppSecret

func WithAppSecret(appSecret string) Option

WithAppSecret to set app secret

func WithClient

func WithClient(cli *http.Client) Option

WithClient use custom *http.Client

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout to set http client timeout. Worked when Options.Client is not set

func WithURL

func WithURL(url string) Option

WithURL to set url

type Options

type Options struct {
	URL         string
	AppKey      string
	AppSecret   string
	AccessToken string
	Timeout     time.Duration
	Client      *http.Client
}

Options for http client

type RequestOption

type RequestOption func(*RequestOptions)

RequestOption use to set addition info to request

func WithHeader

func WithHeader(h nhttp.Header) RequestOption

WithHeader set request header

type RequestOptions

type RequestOptions struct {
	// Request Header
	Header nhttp.Header
}

RequestOptions use to set additional information for the request

Jump to

Keyboard shortcuts

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