base

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustInt

func MustInt(n json.Number) int

Types

type BasicResp

type BasicResp struct {
	// Response state
	State bool `json:"state"`
	// Possible error code fields
	ErrorCode  IntNumber `json:"errno,omitempty"`
	ErrorCode2 int       `json:"errNo,omitempty"`
	ErrorCode3 int       `json:"errcode,omitempty"`
	ErrorCode4 int       `json:"errCode,omitempty"`
	ErrorCode5 int       `json:"code,omitempty"`
	// Possible error message fields
	ErrorMessage  string `json:"error,omitempty"`
	ErrorMessage2 string `json:"message,omitempty"`
	ErrorMessage3 string `json:"error_msg,omitempty"`
}

BasicResp is the basic response for most JSON/JSONP API.

func (*BasicResp) Err

func (r *BasicResp) Err() error

type Boolean

type Boolean bool

func (*Boolean) UnmarshalJSON

func (b *Boolean) UnmarshalJSON(data []byte) (err error)

type FloatNumner

type FloatNumner float64

FloatNumner uses for JSON field which maybe a string or an float number.

func (FloatNumner) Float64

func (n FloatNumner) Float64() float64

func (*FloatNumner) UnmarshalJSON

func (n *FloatNumner) UnmarshalJSON(b []byte) (err error)

type IntNumber

type IntNumber int64

IntNumber uses for JSON field which maybe a string or an integer number.

func (IntNumber) Int

func (n IntNumber) Int() int

func (IntNumber) Int64

func (n IntNumber) Int64() int64

func (IntNumber) String

func (n IntNumber) String() string

func (*IntNumber) UnmarshalJSON

func (n *IntNumber) UnmarshalJSON(b []byte) (err error)

type JsonApiSpec

type JsonApiSpec[D, R any] struct {

	// The API result, its value will be filled after |Parse| called.
	Result D
	// contains filtered or unexported fields
}

JsonApiSpec is the base spec for all JSON ApiSpec.

Type parameters:

  • D: Result type.
  • R: Response type.

func (*JsonApiSpec) EnableCrypto

func (s *JsonApiSpec) EnableCrypto()

func (*JsonApiSpec[D, R]) FormSet

func (s *JsonApiSpec[D, R]) FormSet(key, value string)

func (*JsonApiSpec[D, R]) FormSetAll

func (s *JsonApiSpec[D, R]) FormSetAll(params map[string]string)

func (*JsonApiSpec[D, R]) FormSetInt

func (s *JsonApiSpec[D, R]) FormSetInt(key string, value int)

func (*JsonApiSpec[D, R]) FormSetInt64

func (s *JsonApiSpec[D, R]) FormSetInt64(key string, value int64)

func (*JsonApiSpec[D, R]) Init

func (s *JsonApiSpec[D, R]) Init(baseUrl string)

func (*JsonApiSpec) IsCrypto

func (s *JsonApiSpec) IsCrypto() bool

func (*JsonApiSpec[D, R]) Parse

func (s *JsonApiSpec[D, R]) Parse(r io.Reader) (err error)

func (*JsonApiSpec[D, R]) Payload

func (s *JsonApiSpec[D, R]) Payload() protocol.Payload

func (*JsonApiSpec) QueryGet

func (s *JsonApiSpec) QueryGet(key string) string

func (*JsonApiSpec) QuerySet

func (s *JsonApiSpec) QuerySet(key, value string)

func (*JsonApiSpec) QuerySetInt

func (s *JsonApiSpec) QuerySetInt(key string, value int)

func (*JsonApiSpec) QuerySetInt64

func (s *JsonApiSpec) QuerySetInt64(key string, value int64)

func (*JsonApiSpec) QuerySetNow

func (s *JsonApiSpec) QuerySetNow(key string)

func (*JsonApiSpec) SetBaseUrl

func (s *JsonApiSpec) SetBaseUrl(baseUrl string)

func (*JsonApiSpec) SetCryptoKey

func (s *JsonApiSpec) SetCryptoKey(key string)

func (*JsonApiSpec) Url

func (s *JsonApiSpec) Url() string

Url implements ApiSpec.Url()

type JsonpApiSpec

type JsonpApiSpec[D, R any] struct {

	// The API result, its value will be filled after |Parse| called.
	Result D
	// contains filtered or unexported fields
}

JsonpApiSpec is the base spec for all JSON-P ApiSpec.

Type parameters:

  • D: Result type.
  • R: Response type.

func (*JsonpApiSpec) EnableCrypto

func (s *JsonpApiSpec) EnableCrypto()

func (*JsonpApiSpec[D, R]) Init

func (s *JsonpApiSpec[D, R]) Init(baseUrl, cb string)

func (*JsonpApiSpec) IsCrypto

func (s *JsonpApiSpec) IsCrypto() bool

func (*JsonpApiSpec[D, R]) Parse

func (s *JsonpApiSpec[D, R]) Parse(r io.Reader) (err error)

func (*JsonpApiSpec[D, R]) Payload

func (s *JsonpApiSpec[D, R]) Payload() protocol.Payload

func (*JsonpApiSpec) QueryGet

func (s *JsonpApiSpec) QueryGet(key string) string

func (*JsonpApiSpec) QuerySet

func (s *JsonpApiSpec) QuerySet(key, value string)

func (*JsonpApiSpec) QuerySetInt

func (s *JsonpApiSpec) QuerySetInt(key string, value int)

func (*JsonpApiSpec) QuerySetInt64

func (s *JsonpApiSpec) QuerySetInt64(key string, value int64)

func (*JsonpApiSpec) QuerySetNow

func (s *JsonpApiSpec) QuerySetNow(key string)

func (*JsonpApiSpec) SetBaseUrl

func (s *JsonpApiSpec) SetBaseUrl(baseUrl string)

func (*JsonpApiSpec) SetCryptoKey

func (s *JsonpApiSpec) SetCryptoKey(key string)

func (*JsonpApiSpec) Url

func (s *JsonpApiSpec) Url() string

Url implements ApiSpec.Url()

type M115ApiSpec

type M115ApiSpec[D any] struct {

	// Final result.
	Result D
	// contains filtered or unexported fields
}

M115ApiSpec is the base struct for all m115 ApiSpec.

func (*M115ApiSpec) EnableCrypto

func (s *M115ApiSpec) EnableCrypto()

func (*M115ApiSpec[D]) Init

func (s *M115ApiSpec[D]) Init(baseUrl string, ex M115Extractor[D])

func (*M115ApiSpec) IsCrypto

func (s *M115ApiSpec) IsCrypto() bool

func (*M115ApiSpec[D]) ParamSet

func (s *M115ApiSpec[D]) ParamSet(key, value string)

func (*M115ApiSpec[D]) ParamSetAll

func (s *M115ApiSpec[D]) ParamSetAll(params map[string]string)

func (*M115ApiSpec[D]) Parse

func (s *M115ApiSpec[D]) Parse(r io.Reader) (err error)

Parse implements |ApiSpec.Parse|.

func (*M115ApiSpec[D]) Payload

func (s *M115ApiSpec[D]) Payload() protocol.Payload

Payload implements |ApiSpec.Payload|.

func (*M115ApiSpec) QueryGet

func (s *M115ApiSpec) QueryGet(key string) string

func (*M115ApiSpec) QuerySet

func (s *M115ApiSpec) QuerySet(key, value string)

func (*M115ApiSpec) QuerySetInt

func (s *M115ApiSpec) QuerySetInt(key string, value int)

func (*M115ApiSpec) QuerySetInt64

func (s *M115ApiSpec) QuerySetInt64(key string, value int64)

func (*M115ApiSpec) QuerySetNow

func (s *M115ApiSpec) QuerySetNow(key string)

func (*M115ApiSpec) SetBaseUrl

func (s *M115ApiSpec) SetBaseUrl(baseUrl string)

func (*M115ApiSpec) SetCryptoKey

func (s *M115ApiSpec) SetCryptoKey(key string)

func (*M115ApiSpec) Url

func (s *M115ApiSpec) Url() string

Url implements ApiSpec.Url()

type M115Extractor

type M115Extractor[D any] func([]byte, *D) error

type PayloadImpl

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

func (*PayloadImpl) ContentLength

func (pi *PayloadImpl) ContentLength() int64

func (*PayloadImpl) ContentType

func (pi *PayloadImpl) ContentType() string

func (*PayloadImpl) Read

func (pi *PayloadImpl) Read(p []byte) (int, error)

type StandardResp

type StandardResp struct {
	BasicResp
	Data json.RawMessage `json:"data"`
}

func (*StandardResp) Extract

func (r *StandardResp) Extract(v any) error

type VoidResult

type VoidResult struct{}

VoidResult can be used as result type parameter in ApiSpec, when we do not care about result data from API.

Jump to

Keyboard shortcuts

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