rest_api_client

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsResponseOK

func IsResponseOK(resp Response, err error) bool

Types

type Auth

type Auth interface {
	MakeHeaders(ctx op_context.Context, operation api.Operation, cmd interface{}) (map[string]string, error)
	HandleResponse(resp Response)
}

type Client

type Client struct {
	RestApiClient RestApiClient
	// contains filtered or unexported fields
}

func New

func New(restApiClient RestApiClient, auth ...Auth) *Client

func (*Client) Exec

func (cl *Client) Exec(ctx op_context.Context, operation api.Operation, cmd interface{}, response interface{}, tenancyPath ...string) error

func (*Client) SetPropagateAuthUser

func (cl *Client) SetPropagateAuthUser(val bool)

func (*Client) SetPropagateContextId

func (cl *Client) SetPropagateContextId(val bool)

func (*Client) Transport

func (cl *Client) Transport() interface{}

type ClientAuthSignature

type ClientAuthSignature struct {
	Signer          crypt_utils.ESigner
	EndpoindsConfig auth.EndpointsAuthConfig
}

func (*ClientAuthSignature) HandleResponse

func (a *ClientAuthSignature) HandleResponse(resp Response)

func (*ClientAuthSignature) MakeHeaders

func (a *ClientAuthSignature) MakeHeaders(ctx op_context.Context, operation api.Operation, cmd interface{}) (map[string]string, error)

type ClientAuthSignatureBase

type ClientAuthSignatureBase struct {
	ClientAuthSignatureBaseConfig
	ClientAuthSignature
	// contains filtered or unexported fields
}

func NewClientAuthSignature

func NewClientAuthSignature() *ClientAuthSignatureBase

func (*ClientAuthSignatureBase) Config

func (a *ClientAuthSignatureBase) Config() interface{}

func (*ClientAuthSignatureBase) Init

func (a *ClientAuthSignatureBase) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

type ClientAuthSignatureBaseConfig

type ClientAuthSignatureBaseConfig struct {
	PRIVATE_KEY_FILE     string `validate:"required"`
	PRIVATE_KEY_PASSWORD string `mask:"true"`
}

type ClientAuthSms

type ClientAuthSms struct {
	// contains filtered or unexported fields
}

func NewClientAuthSms

func NewClientAuthSms() *ClientAuthSms

func (*ClientAuthSms) HandleResponse

func (a *ClientAuthSms) HandleResponse(resp Response)

func (*ClientAuthSms) MakeHeaders

func (a *ClientAuthSms) MakeHeaders(ctx op_context.Context, operation api.Operation, cmd interface{}) (map[string]string, error)

func (*ClientAuthSms) SetCode

func (a *ClientAuthSms) SetCode(code string)

type DoRequest

type DoRequest = func(ctx op_context.Context, httpClient *http_request.HttpClient, method string, path string, cmd interface{}, headers ...map[string]string) (Response, error)

type HttpResponse

type HttpResponse struct {
	Raw *http.Response
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(raw *http.Response) (*HttpResponse, error)

func (*HttpResponse) Body

func (r *HttpResponse) Body() []byte

func (*HttpResponse) Code

func (r *HttpResponse) Code() int

func (*HttpResponse) Error

func (r *HttpResponse) Error() generic_error.Error

func (*HttpResponse) Header

func (r *HttpResponse) Header() http.Header

func (*HttpResponse) Message

func (r *HttpResponse) Message() string

func (*HttpResponse) SetError

func (r *HttpResponse) SetError(err generic_error.Error)

type Response

type Response interface {
	Code() int
	Header() http.Header
	Body() []byte
	Message() string

	Error() generic_error.Error
	SetError(err generic_error.Error)
}

func DefaultSendWithBody

func DefaultSendWithBody(ctx op_context.Context, httpClient *http_request.HttpClient, method string, url string, cmd interface{}, headers ...map[string]string) (Response, error)

func DefaultSendWithQuery

func DefaultSendWithQuery(ctx op_context.Context, httpClient *http_request.HttpClient, method string, url string, cmd interface{}, headers ...map[string]string) (Response, error)

type RestApiClient

type RestApiClient interface {
	Url(path string) string

	Login(ctx op_context.Context, user string, password string) (Response, error)
	Logout(ctx op_context.Context) (Response, error)

	UpdateTokens(ctx op_context.Context) (Response, error)
	UpdateCsrfToken(ctx op_context.Context) (Response, error)
	RequestRefreshToken(ctx op_context.Context) (Response, error)

	Post(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)
	Put(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)
	Patch(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)
	Get(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)
	Delete(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

	SendSmsConfirmation(send DoRequest, ctx op_context.Context, resp Response, code string, method string, url string, cmd interface{}, headers ...map[string]string) (Response, error)
}

type RestApiClientBase

type RestApiClientBase struct {
	BaseUrl   string
	UserAgent string
	Tenancy   *TenancyAuth

	AccessToken  string
	RefreshToken string
	CsrfToken    string

	SendWithBody  DoRequest
	SendWithQuery DoRequest

	HttpClient *http_request.HttpClient
}

func DefaultRestApiClient

func DefaultRestApiClient(httpClient *http_request.HttpClient, baseUrl string, userAgent ...string) *RestApiClientBase

func NewRestApiClientBase

func NewRestApiClientBase(withBodySender DoRequest, withQuerySender DoRequest) *RestApiClientBase

func (*RestApiClientBase) AuthPath

func (r *RestApiClientBase) AuthPath(path string) string

func (*RestApiClientBase) Construct

func (r *RestApiClientBase) Construct(withBodySender DoRequest, withQuerySender DoRequest)

func (*RestApiClientBase) Delete

func (r *RestApiClientBase) Delete(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) Get

func (r *RestApiClientBase) Get(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) Init

func (r *RestApiClientBase) Init(httpClient *http_request.HttpClient, baseUrl string, userAgent string, tenancy ...*TenancyAuth)

func (*RestApiClientBase) Login

func (r *RestApiClientBase) Login(ctx op_context.Context, user string, password string) (Response, error)

func (*RestApiClientBase) Logout

func (*RestApiClientBase) Patch

func (r *RestApiClientBase) Patch(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) Post

func (r *RestApiClientBase) Post(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) Prepare

func (r *RestApiClientBase) Prepare(ctx op_context.Context) (Response, error)

func (*RestApiClientBase) Put

func (r *RestApiClientBase) Put(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) RequestBody

func (r *RestApiClientBase) RequestBody(ctx op_context.Context, method string, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) RequestQuery

func (r *RestApiClientBase) RequestQuery(ctx op_context.Context, method string, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) RequestRefreshToken

func (r *RestApiClientBase) RequestRefreshToken(ctx op_context.Context) (Response, error)

func (*RestApiClientBase) SendRequest

func (r *RestApiClientBase) SendRequest(send DoRequest, ctx op_context.Context, method string, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) SendSmsConfirmation

func (r *RestApiClientBase) SendSmsConfirmation(send DoRequest, ctx op_context.Context, resp Response, code string, method string, path string, cmd interface{}, headers ...map[string]string) (Response, error)

func (*RestApiClientBase) SetRefreshToken

func (r *RestApiClientBase) SetRefreshToken(token string)

func (*RestApiClientBase) UpdateCsrfToken

func (r *RestApiClientBase) UpdateCsrfToken(ctx op_context.Context) (Response, error)

func (*RestApiClientBase) UpdateTokens

func (r *RestApiClientBase) UpdateTokens(ctx op_context.Context) (Response, error)

func (*RestApiClientBase) Url

func (r *RestApiClientBase) Url(path string) string

type RestApiClientWithConfig

type RestApiClientWithConfig struct {
	RestApiClientWithConfigCfg
	*RestApiClientBase

	http_request.WithHttpClient
}

func DefaultRestApiClientWithConfig

func DefaultRestApiClientWithConfig() *RestApiClientWithConfig

func NewAutoReconnectRestApiClient

func NewAutoReconnectRestApiClient(reconnectHandlers api_client.AutoReconnectHandlers) *RestApiClientWithConfig

func NewRestApiClientWithConfig

func NewRestApiClientWithConfig(withBodySender DoRequest, withQuerySender DoRequest) *RestApiClientWithConfig

func (*RestApiClientWithConfig) Config

func (r *RestApiClientWithConfig) Config() interface{}

func (*RestApiClientWithConfig) Init

func (r *RestApiClientWithConfig) Init(cfg config.Config, log logger.Logger, vld validator.Validator, configPath ...string) error

type RestApiClientWithConfigCfg

type RestApiClientWithConfigCfg struct {
	BASE_URL     string `validate:"required"`
	USER_AGENT   string `default:"go-backend-helpers"`
	TENANCY_TYPE string `default:"tenancy"`
	TENANCY_PATH string
}

type RestApiMethod

type RestApiMethod func(ctx op_context.Context, path string, cmd interface{}, response interface{}, headers ...map[string]string) (Response, error)

type TenancyAuth

type TenancyAuth struct {
	TenancyPath string
	TenancyType string
}

Jump to

Keyboard shortcuts

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