rest

package module
v0.5.17 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-3-Clause Imports: 22 Imported by: 4

README

GoDoc

rest API

Allows accessing functions from the rest api.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug  = false
	Scheme = "https"
	Host   = "www.atonline.com"
)
View Source
var (
	ErrNoClientID     = errors.New("no client_id has been provided for token renewal")
	ErrNoRefreshToken = errors.New("no refresh token is available and access token has expired")
)
View Source
var ErrLoginRequired = errors.New("login required")
View Source
var RestHttpClient = &http.Client{
	Transport: RestHttpTransport,
	Timeout:   300 * time.Second,
}
View Source
var RestHttpTransport = &http.Transport{
	Proxy:                 http.ProxyFromEnvironment,
	MaxIdleConns:          100,
	MaxIdleConnsPerHost:   50,
	MaxConnsPerHost:       200,
	IdleConnTimeout:       90 * time.Second,
	ResponseHeaderTimeout: 90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 5 * time.Second,
}
View Source
var (
	SystemProxy = &httputil.ReverseProxy{
		Director:  systemProxyDirector,
		Transport: RestHttpClient.Transport,
	}
)

Functions

func Apply

func Apply(ctx context.Context, req, method string, param any, target any) error

Types

type ContextRequest added in v0.5.6

type ContextRequest int
const (
	BackendURL   ContextRequest = 1
	SkipDebugLog ContextRequest = 2
)

type Error added in v0.2.2

type Error struct {
	Response *Response
	// contains filtered or unexported fields
}

func (*Error) Error added in v0.2.2

func (r *Error) Error() string

func (*Error) Unwrap added in v0.4.5

func (r *Error) Unwrap() error

type HttpError added in v0.5.15

type HttpError struct {
	Code int
	Body []byte
	// contains filtered or unexported fields
}

func (*HttpError) Error added in v0.5.15

func (e *HttpError) Error() string

func (*HttpError) Unwrap added in v0.5.15

func (e *HttpError) Unwrap() error

type Param added in v0.2.2

type Param map[string]any

type Response added in v0.2.2

type Response struct {
	Result string           `json:"result"` // "success" or "error" (or "redirect")
	Data   pjson.RawMessage `json:"data,omitempty"`
	Error  string           `json:"error,omitempty"`
	Code   int              `json:"code,omitempty"` // for errors
	Extra  string           `json:"extra,omitempty"`
	Token  string           `json:"token,omitempty"`

	Paging any `json:"paging,omitempty"`
	Job    any `json:"job,omitempty"`
	Time   any `json:"time,omitempty"`
	Access any `json:"access,omitempty"`

	Exception    string `json:"exception,omitempty"`
	RedirectUrl  string `json:"redirect_url,omitempty"`
	RedirectCode int    `json:"redirect_code,omitempty"`
	// contains filtered or unexported fields
}

func Do

func Do(ctx context.Context, req, method string, param any) (*Response, error)

func Upload added in v0.4.0

func Upload(ctx context.Context, req, method string, param Param, f io.Reader, mimeType string) (*Response, error)

func (*Response) Apply added in v0.4.2

func (r *Response) Apply(v any) error

func (*Response) ApplyContext added in v0.5.3

func (r *Response) ApplyContext(ctx context.Context, v any) error

func (*Response) FullRaw added in v0.5.10

func (r *Response) FullRaw() (map[string]any, error)

FullRaw fetches the whole raw object including "Response" own data

func (*Response) Get added in v0.4.4

func (r *Response) Get(v string) (any, error)

func (*Response) GetString added in v0.4.4

func (r *Response) GetString(v string) (string, error)

func (*Response) OffsetGet added in v0.5.11

func (r *Response) OffsetGet(ctx context.Context, key string) (any, error)

func (*Response) ParseData added in v0.5.12

func (r *Response) ParseData()

func (*Response) Raw added in v0.5.7

func (r *Response) Raw() (any, error)

Raw is implemented as r.Value() for compatibility

func (*Response) ReadValue added in v0.2.2

func (r *Response) ReadValue(ctx context.Context) (any, error)

func (*Response) Value added in v0.4.4

func (r *Response) Value() (any, error)

func (*Response) ValueContext added in v0.5.3

func (r *Response) ValueContext(ctx context.Context) (any, error)

type RouterType added in v0.1.3

type RouterType struct {
}
var Router *RouterType = &RouterType{}

func (*RouterType) ServeHTTP added in v0.1.3

func (h *RouterType) ServeHTTP(w http.ResponseWriter, req *http.Request)

type SenderInterface added in v0.5.1

type SenderInterface interface {
	Send(from string, to []string, msg io.WriterTo) error
}
var Sender SenderInterface = restSender{}

type Time added in v0.1.4

type Time struct {
	time.Time
}

func (Time) MarshalContextJSON added in v0.5.3

func (u Time) MarshalContextJSON(ctx context.Context) ([]byte, error)

func (Time) MarshalJSON added in v0.3.0

func (u Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalContextJSON added in v0.5.3

func (u *Time) UnmarshalContextJSON(ctx context.Context, data []byte) error

func (*Time) UnmarshalJSON added in v0.3.0

func (u *Time) UnmarshalJSON(data []byte) error

type Token added in v0.2.0

type Token struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	Type         string `json:"token_type"`
	ClientID     string
	Expires      int `json:"expires_in"`
}

func (*Token) Use added in v0.2.0

func (t *Token) Use(ctx context.Context) context.Context

type UploadInfo added in v0.4.0

type UploadInfo struct {
	MaxPartSize     int64 // maximum size of a single part in MB, defaults to 1024 (1GB)
	ParallelUploads int   // number of parallel uploads to perform (defaults to 3)
	// contains filtered or unexported fields
}

func PrepareUpload added in v0.4.0

func PrepareUpload(req map[string]any) (*UploadInfo, error)

upload for platform files

func (*UploadInfo) Do added in v0.4.0

func (u *UploadInfo) Do(ctx context.Context, f io.Reader, mimeType string, ln int64) (*Response, error)

func (*UploadInfo) String added in v0.4.0

func (u *UploadInfo) String() string

Jump to

Keyboard shortcuts

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