api

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERRORS = map[int]string{
	100: "unknown error.",
	101: "missing api, version, or method parameter",
	102: "the requested API does not exist",
	103: "the requested method does not exist",
	104: "the requested version does not support the functionality",
	105: "the logged in session does not have permission",
	106: "session timeout",
	107: "session interrupted by duplicated login",
	108: "failed to upload file",
	109: "the network connection is unstable or the system is busy",
	110: "the network connection is unstable or the system is busy",
	111: "the network connection is unstable or the system is busy",
	114: "lost parameters for this API",
	115: "not allowed to upload a file",
	116: "not allowed to perform for a demo site.",
	117: "the network connection is unstable or the system is busy",
	118: "the network connection is unstable or the system is busy",
	119: "invalid session",
	150: "request source IP does not match the login IP",

	400: "No such account or incorrect password",
	401: "Disabled account",
	402: "Denied permission",
	403: "2-factor authentication code required",
	404: "Failed to authenticate 2-factor authentication code",
	406: "Enforce to authenticate with 2-factor authentication code",
	407: "Blocked IP source",
	408: "Expired password cannot change",
	409: "Expired password",
	410: "Password must be changed",
}

Functions

func SetLogger

func SetLogger(logger *zap.Logger)

SetLogger overrides the default no-op zap.Logger with a user-provided logger. Use this for debug logging of http requests and responses.

func WrapQuote

func WrapQuote(s string) string

Types

type Authorizer

type Authorizer interface {
	Apply(values url.Values)
}

type Client

type Client interface {
	NewGET(transformer ValueTransformer) (*http.Request, error)
	NewPOST(transformer ValueTransformer) (*http.Request, error)
}

func NewClient

func NewClient(baseURL string, authorizer Authorizer) Client

type Error

type Error map[string]interface{}

func (Error) ErrorCode

func (e Error) ErrorCode() int

func (Error) ErrorCodeDescription

func (e Error) ErrorCodeDescription() string

type ListResponse

type ListResponse struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
	Total  int `json:"total"`
}

type NoopAuthorizer

type NoopAuthorizer struct {
}

func (NoopAuthorizer) Apply

func (noop NoopAuthorizer) Apply(_ url.Values)

type ResponseWrapper

type ResponseWrapper[T any] struct {
	Data    T     `json:"data"`
	Error   Error `json:"error"`
	Success bool  `json:"success"`
}

func GET

func GET[T any](client Client, queryTransformer func(query url.Values)) (*ResponseWrapper[T], error)

func POST

func POST[T any](client Client, queryTransformer func(query url.Values)) (*ResponseWrapper[T], error)

func ParseResponse

func ParseResponse[T any](responseBody io.Reader) (*ResponseWrapper[T], error)

func PerformRequest

func PerformRequest[T any](req *http.Request) (*ResponseWrapper[T], error)

type TestServer

type TestServer struct {
	Requests   []*http.Request
	HTTPServer *httptest.Server
	// contains filtered or unexported fields
}

func FakeServerHandler

func FakeServerHandler() *TestServer

func (*TestServer) AddRoute

func (t *TestServer) AddRoute(httpMethod, api, apiMethod string, handler http.HandlerFunc)

func (*TestServer) ServeHTTP

func (t *TestServer) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*TestServer) Session

func (t *TestServer) Session() string

type ValueTransformer

type ValueTransformer = func(values url.Values)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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