package module
Version: v1.0.3 Latest Latest

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

Go to latest
Published: May 6, 2021 License: AGPL-3.0 Imports: 14 Imported by: 0


Basic http client in go

This repo provides a basic http client in go.




View Source
const (
	MsgErrCannotObtain              = "cannotObtain"
	MsgErrCannotUnmarshal           = "cannotUnmarshal"
	MsgErrCannotParse               = "cannotParse"
	MsgErrUnkownHTTPContentType     = "unkownHTTPContentType"
	MsgErrUnknownResponseStatusCode = "unknownResponseStatusCode"

	PrmTokenProviderURL = "tokenProviderURL"
	PrmAPIURL           = "APIURL"
	PrmTokenMsg         = "token"
	PrmResponse         = "response"

Constants for error management


This section is empty.


func CreateQueryPlugins

func CreateQueryPlugins(paramKV ...string) []plugin.Plugin

CreateQueryPlugins create query parameters with the key values paramKV.

func SetAccessToken

func SetAccessToken(accessToken string) plugin.Plugin

SetAccessToken creates a plugin to set an access token which is a valid token

func SetAccessTokenE

func SetAccessTokenE(accessToken string) (plugin.Plugin, error)

SetAccessTokenE creates a plugin to set an access token


type Client

type Client struct {
	// contains filtered or unexported fields

Client is the HTTP client.

func New

func New(addrAPI string, reqTimeout time.Duration, reqUpdaters ...func(*gentleman.Request) (*gentleman.Request, error)) (*Client, error)

New returns a keycloak client.

func NewBasicAuthClient

func NewBasicAuthClient(addrAPI string, reqTimeout time.Duration, username, password string) (*Client, error)

NewBasicAuthClient creates a new HTTP client using a basic authentication

func NewBearerAuthClient

func NewBearerAuthClient(addrAPI string, reqTimeout time.Duration, tokenProvider func() (string, error)) (*Client, error)

NewBearerAuthClient creates a new HTTP client using a bearer authentication

func (*Client) Delete

func (c *Client) Delete(plugins ...plugin.Plugin) error

Delete is a HTTP DELETE method

func (*Client) Get

func (c *Client) Get(data interface{}, plugins ...plugin.Plugin) error

Get is a HTTP GET method.

func (*Client) Post

func (c *Client) Post(data interface{}, plugins ...plugin.Plugin) (string, error)

Post is a HTTP POST method

func (*Client) Put

func (c *Client) Put(plugins ...plugin.Plugin) error

Put is a HTTP PUT method

type HTTPError

type HTTPError struct {
	StatusCode int
	Message    string

HTTPError is returned when an error occured while contacting the keycloak instance.

func (HTTPError) Error

func (e HTTPError) Error() string

func (HTTPError) ErrorMessage

func (e HTTPError) ErrorMessage() string

ErrorMessage returns the HTTP error message

func (HTTPError) IsError

func (e HTTPError) IsError() bool

IsError is true when HTTP request failed

func (HTTPError) IsErrorFromClient

func (e HTTPError) IsErrorFromClient() bool

IsErrorFromClient is true when HTTP request failed and the cause was related to the client request

func (HTTPError) IsErrorFromServer

func (e HTTPError) IsErrorFromServer() bool

IsErrorFromServer is true when HTTP request failed and the cause was related to the HTTP server

func (HTTPError) IsSuccess

func (e HTTPError) IsSuccess() bool

IsSuccess is true when HTTP status code is 2xx or 3xx

func (HTTPError) Status

func (e HTTPError) Status() int

Status returns the HTTP status code

type Token

type Token struct {
	Issuer         string `json:"iss,omitempty"`
	Subject        string `json:"sub,omitempty"`
	ExpirationTime int64  `json:"exp,omitempty"`
	NotBefore      int64  `json:"nbf,omitempty"`
	IssuedAt       int64  `json:"iat,omitempty"`
	ID             string `json:"jti,omitempty"`
	Username       string `json:"preferred_username,omitempty"`
	// contains filtered or unexported fields

Token is JWT token. We need to define our own structure as the library define aud as a string but it can also be a string array. To fix this issue, we remove aud as we do not use it here.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL