apiclient

package module
v1.0.33 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2025 License: MIT Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	AllowInsecureSSL   bool
	Timeout            time.Duration
	Debug              bool
	ResourceAPIBaseURL string

	StructuredResponse bool
	BasicAuthUser      string
	BasicAuthPwd       string
	UseBasicAuth       bool
	// contains filtered or unexported fields
}

API - provide functions to call APIs using GET, POST, PUT, DELETE methods to any API. It will return RawReuslt{}. API response will be read and set as string into RawResult.Data that client can parse.

func (*API) ClearHeaders added in v1.0.32

func (j *API) ClearHeaders()

func (API) DebugEnabled

func (j API) DebugEnabled() bool

func (*API) Delete added in v1.0.3

func (a *API) Delete(apipath string) (APIResult, error)

Delete - make HTTP DELETE request to given api path and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*API) DeleteURL added in v1.0.3

func (a *API) DeleteURL(apiurl string) (APIResult, error)

DeleteURL - make HTTP DELETE request to given url and return RawResult{}.

func (*API) Get

func (a *API) Get(apipath string) (APIResult, error)

Get - make HTTP GET request to given api path and return RawResult{}.

func (API) GetBaseURL added in v1.0.1

func (j API) GetBaseURL() string

func (API) GetTimeout

func (j API) GetTimeout() time.Duration

func (*API) GetURL added in v1.0.3

func (a *API) GetURL(apiurl string) (APIResult, error)

GetURL - make HTTP GET request to given url and return RawResult{}.

func (API) InsecureSSLEnabled

func (j API) InsecureSSLEnabled() bool

func (*API) Patch added in v1.0.33

func (a *API) Patch(apipath string, putdataJSON []byte) (APIResult, error)

Patch - make HTTP PATCH request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*API) PatchURL added in v1.0.33

func (a *API) PatchURL(apiurl string, patchdataJSON []byte) (APIResult, error)

PatchURL - make HTTP PATCH request to given url and post JSON data and return RawResult{}.

func (*API) Post added in v1.0.3

func (a *API) Post(apipath string, postdataJSON []byte) (APIResult, error)

Post - make HTTP POST request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*API) PostForm added in v1.0.3

func (a *API) PostForm(apiurl string, data map[string]string) (APIResult, error)

PostForm - make HTTP POST request to given url with content-type: application/x-www-form-urlencoded

func (*API) PostURL added in v1.0.3

func (a *API) PostURL(apiurl string, postdataJSON []byte) (APIResult, error)

PostURL - make HTTP POST request to given url and post JSON data and return RawResult{}.

func (*API) Put added in v1.0.3

func (a *API) Put(apipath string, putdataJSON []byte) (APIResult, error)

Put - make HTTP PUT request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*API) PutURL added in v1.0.3

func (a *API) PutURL(apiurl string, putdataJSON []byte) (APIResult, error)

PutURL - make HTTP PUT request to given url and post JSON data and return RawResult{}.

func (*API) SetHeaders added in v1.0.32

func (j *API) SetHeaders(h map[string]string)

func (*API) SetLogWriter added in v1.0.3

func (a *API) SetLogWriter(w io.Writer)

SetLogWriter Sets io.writer for logging to file

type APIResult

type APIResult struct {
	HTTPStatus int
	ErrCode    int
	ErrText    string
	//ErrValid tells if ErrCode and ErrText hold values from result from API or just defalut values
	ErrValid bool
	//Data hold resultant JSON as string
	Data string //interface{}
}

APIResult is structured response returned from APIs developed by samtech09

type JwtAPI

type JwtAPI struct {
	TokenRequestData TokenRequest

	TokenURI           string
	RefreshTokenURI    string
	AllowInsecureSSL   bool
	Timeout            time.Duration
	Debug              bool
	ResourceAPIBaseURL string

	StructuredResponse bool
	// contains filtered or unexported fields
}

JwtAPI provide functions to call JWT protected APIs by setting Access-Token in request Authorization header

func (*JwtAPI) ClearHeaders added in v1.0.32

func (j *JwtAPI) ClearHeaders()

func (JwtAPI) DebugEnabled

func (j JwtAPI) DebugEnabled() bool

func (*JwtAPI) Delete

func (j *JwtAPI) Delete(apipath string) (APIResult, error)

Delete - make HTTP DELETE request to given api path and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*JwtAPI) DeleteURL added in v1.0.1

func (j *JwtAPI) DeleteURL(apiurl string) (APIResult, error)

DeleteURL - call given apiurl with DELETE method, auto inject Authorization Header, returns RawResult{}.

func (*JwtAPI) Get

func (j *JwtAPI) Get(apipath string) (APIResult, error)

Get - make HTTP GET request to given api path and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (JwtAPI) GetBaseURL added in v1.0.1

func (j JwtAPI) GetBaseURL() string

func (JwtAPI) GetRefreshTokenURI

func (j JwtAPI) GetRefreshTokenURI() string

func (JwtAPI) GetTimeout

func (j JwtAPI) GetTimeout() time.Duration

func (JwtAPI) GetToken

func (j JwtAPI) GetToken() Token

func (JwtAPI) GetTokenRequestData

func (j JwtAPI) GetTokenRequestData() TokenRequest

func (JwtAPI) GetTokenURI

func (j JwtAPI) GetTokenURI() string

func (*JwtAPI) GetURL added in v1.0.1

func (j *JwtAPI) GetURL(apiurl string) (APIResult, error)

GetURL - call given apiurl with GET method, auto inject Authorization Header, returns RawResult{}.

func (JwtAPI) InsecureSSLEnabled

func (j JwtAPI) InsecureSSLEnabled() bool

func (*JwtAPI) Patch added in v1.0.33

func (j *JwtAPI) Patch(apipath string, patchdataJSON []byte) (APIResult, error)

Post - make HTTP PATCH request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*JwtAPI) PatchURL added in v1.0.33

func (j *JwtAPI) PatchURL(apiurl string, patchdataJSON []byte) (APIResult, error)

PostURL - call given apiurl with PATCH method and pass data, auto inject Authorization Header, returns RawResult{}.

func (*JwtAPI) Post

func (j *JwtAPI) Post(apipath string, postdataJSON []byte) (APIResult, error)

Post - make HTTP POST request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*JwtAPI) PostURL added in v1.0.1

func (j *JwtAPI) PostURL(apiurl string, postdataJSON []byte) (APIResult, error)

PostURL - call given apiurl with POST method and pass data, auto inject Authorization Header, returns RawResult{}.

func (*JwtAPI) Put

func (j *JwtAPI) Put(apipath string, putdataJSON []byte) (APIResult, error)

Put - make HTTP PUT request to given api path, post JSON data and return APIResult{}. ResourceAPIBaseURL will be prepended.

func (*JwtAPI) PutURL added in v1.0.1

func (j *JwtAPI) PutURL(apiurl string, putdataJSON []byte) (APIResult, error)

PutURL - call given apiurl with PUT method and pass data, auto inject Authorization Header, returns RawResult{}.

func (*JwtAPI) RequestTokenByCred

func (j *JwtAPI) RequestTokenByCred() (Token, error)

RequestTokenByCred call Token endpoint to get new token by passing TokenRequest data. It set token to JwtAPI instance for subsequent calls through same instance.

func (*JwtAPI) RequestTokenByRefreshToken

func (j *JwtAPI) RequestTokenByRefreshToken(rtoken string) (Token, error)

RequestTokenByRefreshToken call Token endpoint to get new token by passing existing refresh-token. It set token to JwtAPI instance for subsequent calls through same instance.

func (*JwtAPI) SetHeaders added in v1.0.32

func (j *JwtAPI) SetHeaders(h map[string]string)

func (*JwtAPI) SetLogWriter added in v1.0.3

func (j *JwtAPI) SetLogWriter(w io.Writer)

SetLogWriter Sets io.writer for logging to file

type Token

type Token struct {
	TokenType    string `json:"token_type"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    string `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

Token is returned after successfull request to token or refreshtoken endpoints

type TokenRequest

type TokenRequest struct {
	ClientID     string
	ClientSecret string
	Scopes       string
	AppUserID    string
	RefreshToken string
}

TokenRequest is used to pass credential to auth-server to get new token

Jump to

Keyboard shortcuts

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