rest

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2020 License: BSD-3-Clause Imports: 14 Imported by: 5

README

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 (*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 {
	Full string `json:"full"`
	TZ   string `json:"tz"`
}

func (*Time) Time added in v0.1.4

func (t *Time) Time() time.Time

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

Jump to

Keyboard shortcuts

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