rest

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2021 License: BSD-3-Clause Imports: 20 Imported by: 5

README

GoDoc

rest API

Allows accessing functions from the rest api.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Debug = false
	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 RestHttpClient = &http.Client{
	Transport: &http.Transport{
		Proxy:                 http.ProxyFromEnvironment,
		MaxIdleConns:          100,
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	},
	Timeout: 120 * 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 Param, target interface{}) error

func RedirectError

func RedirectError(u *url.URL) error

func RedirectErrorCode

func RedirectErrorCode(u *url.URL, code int) error

code can be one of http.StatusMovedPermanently or http.StatusFound or any 3xx http status code

func SendRedirect

func SendRedirect(w http.ResponseWriter, url string, code int)

Types

type Error added in v0.2.2

type Error struct {
	Response *Response
}

func (*Error) Error added in v0.2.2

func (r *Error) Error() string

type Param added in v0.2.2

type Param map[string]interface{}

type Response added in v0.2.2

type Response struct {
	Result string          `json:"result"` // "success" or "error" (or "redirect")
	Data   json.RawMessage `json:"data"`
	Error  string          `json:"error"`
	Extra  string          `json:"extra"`
	Token  string          `json:"token"`

	Paging interface{} `json:"paging"`
	Job    interface{} `json:"job"`
	Time   interface{} `json:"time"`
	Access interface{} `json:"access"`

	RedirectUrl  string `json:"redirect_url"`
	RedirectCode int    `json:"redirect_code"`
}

func Do

func Do(ctx context.Context, req, method string, param Param) (*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 interface{}) error

func (*Response) ReadValue added in v0.2.2

func (r *Response) ReadValue(ctx context.Context) (interface{}, 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 Time added in v0.1.4

type Time struct {
	time.Time
}

func (Time) MarshalJSON added in v0.3.0

func (u Time) MarshalJSON() ([]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]interface{}) (*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