libCallApi

package
v0.13.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuth

func BasicAuth(username, password string) string

func ConsumeRestJSON added in v0.9.52

func ConsumeRestJSON[Resp ApiResp](c *CallData) (*Resp, response.ErrorState)

func GetJSONResp added in v0.9.52

func GetJSONResp[Resp ApiResp](api RemoteApi, resp *http.Response) (*Resp, response.ErrorState)

func PrepareCall

func PrepareCall(c CallData) (*http.Request, response.ErrorState)

func RemoteCall added in v0.9.52

func RemoteCall[Req any, Resp ApiResp](param *RemoteCallParamData[Req]) (*Resp, response.ErrorState)

func TransmitRequestWithAuth

func TransmitRequestWithAuth(
	path, api, method string,
	requestByte []byte,
	headers map[string]string,
	parseRemoteResp func([]byte, string, int) (int, map[string]string, any, error),
	consumeHandler func([]byte, string, string, string, string, map[string]string) ([]byte, string, int, error),
) (int, map[string]string, any, error)

func TransmitSoap

func TransmitSoap[Resp any](request any, url string, debug bool, timeout time.Duration) (*Resp, error)

Types

type ApiResp added in v0.9.56

type ApiResp interface {
	SetStatus(int)
	SetHeaders(map[string]string)
}

type Auth added in v0.12.2

type Auth struct {
	GrantType    string `yaml:"grant-type"`
	User         string `yaml:"user"`
	Password     string `yaml:"password"`
	ClientID     string `yaml:"client-id"`
	ClientSecret string `yaml:"client-secret"`
	AuthURI      string `yaml:"auth-uri"`
}

type AuthSystem added in v0.12.2

type AuthSystem interface {
	Login() (*TokenCache, libError.Error)
}

type CallApiInterface

type CallApiInterface interface {
	GetApi(apiName string) RemoteApi
	ConsumeRestBasicAuthApi(requestJson []byte, apiName, path, contentType, method string, headers map[string]string) ([]byte, string, error)
	ConsumeRestApi(requestJson []byte, apiName, path, contentType, method string, headers map[string]string) ([]byte, string, int, error)
}

type CallData

type CallData struct {
	Api       RemoteApi
	Path      string
	Method    string
	Headers   map[string]string
	Req       any
	SslVerify bool
	BodyType  RequestBodyType
	Timeout   time.Duration
	EnableLog bool
	LogLevel  int
}

func (CallData) SetLogs added in v0.3.3

func (c CallData) SetLogs(req *http.Request) *http.Request

type CallParam added in v0.3.4

type CallParam *CallParamData

type CallParamData added in v0.9.16

type CallParamData struct {
	Parameters  map[string]any
	Headers     map[string]string
	Api         RemoteApi
	Timeout     time.Duration
	Method      string
	Path        string
	Query       string
	QueryStack  *[]string
	ValidateTls bool
	EnableLog   bool
	JsonBody    any
}

type CallResp

type CallResp struct {
	Headers map[string]string
	Status  int
}

func ConsumeRest

func ConsumeRest[Resp any](c CallData) (*Resp, *response.WsRemoteResponse, *CallResp, response.ErrorState)

func GetResp

func GetResp[Resp any, Error any](api RemoteApi, resp *http.Response) (*Resp, *Error, *CallResp, response.ErrorState)

type CallResult added in v0.3.4

type CallResult[RespType any] struct {
	Resp   *RespType
	WsResp *response.WsRemoteResponse
	Status *CallResp
	Error  response.ErrorState
}

func Call added in v0.3.4

func Call[RespType any](param CallParam) CallResult[RespType]

func MultiCall added in v0.3.6

func MultiCall(paramList []CallParam, core CallApiInterface) []CallResult[response.WsRemoteResponse]

type OAuth2Token added in v0.12.2

type OAuth2Token struct {
	Token      string
	Type       string
	Scope      string
	TimeTaken  time.Time
	ValidUntil time.Duration
}

type RemoteApi

type RemoteApi struct {
	Domain         string            `yaml:"domain"`
	Name           string            `yaml:"name"`
	AuthData       Auth              `yaml:"auth"`
	Options        map[string]string `yaml:"options"`
	Auth           AuthSystem        `yaml:"-"`
	TokenCacheLock *sync.Mutex       `yaml:"-"`
	TokenCache     *TokenCache       `yaml:"-"`
}

func (RemoteApi) AddBasicAuthHeader added in v0.12.2

func (api RemoteApi) AddBasicAuthHeader(headers map[string]string) map[string]string

func (*RemoteApi) Authenticate added in v0.12.2

func (api *RemoteApi) Authenticate() libError.Error

func (RemoteApi) GetAuthHeader added in v0.12.4

func (api RemoteApi) GetAuthHeader() (string, error)

func (RemoteApi) GetBasicAuthHeader added in v0.12.2

func (api RemoteApi) GetBasicAuthHeader() string

type RemoteApiModel

type RemoteApiModel struct {
	RemoteApiList map[string]RemoteApi
}

func (RemoteApiModel) ConsumeRestApi

func (m RemoteApiModel) ConsumeRestApi(requestJson []byte, apiName, path, contentType, method string, headers map[string]string) ([]byte, string, int, error)

func (RemoteApiModel) ConsumeRestBasicAuthApi

func (m RemoteApiModel) ConsumeRestBasicAuthApi(requestJson []byte, apiName, path, contentType, method string, headers map[string]string) ([]byte, string, error)

func (RemoteApiModel) GetApi

func (m RemoteApiModel) GetApi(apiName string) RemoteApi

type RemoteCallParamData added in v0.9.52

type RemoteCallParamData[Req any] struct {
	Parameters  map[string]any
	Headers     map[string]string
	Api         RemoteApi
	Timeout     time.Duration
	Method      string
	Path        string
	Query       string
	QueryStack  *[]string
	ValidateTls bool
	EnableLog   bool
	JsonBody    Req
	BodyType    RequestBodyType
}

type RequestBodyType added in v0.11.15

type RequestBodyType int
const (
	JSON RequestBodyType = iota
	Form
	Empty
)

type TokenCache added in v0.12.2

type TokenCache struct {
	AccessToken  *OAuth2Token
	RefreshToken *OAuth2Token
}

func InitTokenCache added in v0.12.4

func InitTokenCache() (*TokenCache, *sync.Mutex)

initilaizes a token cache which will be used across all APIs should be called once per remote-api

func (TokenCache) Expired added in v0.12.9

func (t TokenCache) Expired() bool

type TypeList added in v0.3.6

type TypeList interface {
	GetType(int) any
}

Jump to

Keyboard shortcuts

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