client

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Basic       = AuthorizationType(AuthorizationTypeStruct{HeaderName: "Authorization", HeaderType: "Basic", HeaderTypeValue: "Basic "})
	Bearer      = AuthorizationType(AuthorizationTypeStruct{HeaderName: "Authorization", HeaderType: "Bearer", HeaderTypeValue: "Bearer "})
	AccessToken = AuthorizationType(AuthorizationTypeStruct{HeaderName: "X-Access-Token", HeaderType: "Auth0", HeaderTypeValue: ""})
	Secret      = AuthorizationType(AuthorizationTypeStruct{HeaderName: "Secret", HeaderType: "Secret", HeaderTypeValue: ""})
	APIKey      = AuthorizationType(AuthorizationTypeStruct{HeaderName: "APIKey", HeaderType: "APIKey", HeaderTypeValue: ""})
)

Enum value for http authorization type

Functions

func ParseQueryParams

func ParseQueryParams(path string, params interface{}) string

ParseQueryParams .

func Sethystrix

func Sethystrix(nameClient string)

Sethystrix setting for client

Types

type AcknowledgeRequest

type AcknowledgeRequest struct {
	ID                 int            `json:"id" db:"id"`
	RequestID          int            `json:"requestId" db:"requestId"`
	CommitStatus       string         `json:"commitStatus" db:"commitStatus"`
	ReservedHolder     types.Metadata `json:"reservedHolder" db:"reservedHolder"`
	ReservedHolderName string         `json:"reservedHolderName" db:"reservedHolderName"`
	Message            string         `json:"message" db:"message"`
}

AcknowledgeRequest object of acknowledge request swagger:model

type AcknowledgeRequestService

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

AcknowledgeRequestService represents the services for acknowledge request

func NewAcknowledgeRequestService

func NewAcknowledgeRequestService(
	acknowledgeRequestStorage AcknowledgeRequestStorage,
	clientRequestLog ClientRequestLogStorage,
) *AcknowledgeRequestService

NewAcknowledgeRequestService creates new acknowledge service

func (*AcknowledgeRequestService) Acknowledge

func (s *AcknowledgeRequestService) Acknowledge(ctx *context.Context, status string, message string) error

Acknowledge broadcast status (rollback if failed and commit if succeed) request to all request had been sent before

func (*AcknowledgeRequestService) Create

func (s *AcknowledgeRequestService) Create(ctx *context.Context, acknowledgeRequest *AcknowledgeRequest) error

Create Create log to store the request which needed to be acknowledged

func (*AcknowledgeRequestService) Prepare

Prepare store request log to this services before starting run in transaction

type AcknowledgeRequestServiceInterface

type AcknowledgeRequestServiceInterface interface {
	Acknowledge(ctx *context.Context, status string, message string) error
	Prepare(ctx *context.Context) error
	Create(ctx *context.Context, acknowledgeRequest *AcknowledgeRequest) error
}

AcknowledgeRequestServiceInterface represents an interface segreggation to encapsulate object of AcknowledgeRequest to control commit

type AcknowledgeRequestStorage

type AcknowledgeRequestStorage interface {
	FindAll(ctx *context.Context, params *FindAllAcknowledgeRequests) ([]*AcknowledgeRequest, *types.Error)
	FindByID(ctx *context.Context, acknowledgeRequestID int) (*AcknowledgeRequest, *types.Error)
	Insert(ctx *context.Context, acknowledgeRequest *AcknowledgeRequest) (*AcknowledgeRequest, *types.Error)
	Update(ctx *context.Context, acknowledgeRequest *AcknowledgeRequest) (*AcknowledgeRequest, *types.Error)
	Delete(ctx *context.Context, acknowledgeRequestID int) *types.Error
}

AcknowledgeRequestStorage represents the interface for manage acknowledge request object

type AuthorizationType

type AuthorizationType AuthorizationTypeStruct

AuthorizationType represents the enum for http authorization type

type AuthorizationTypeStruct

type AuthorizationTypeStruct struct {
	HeaderName      string
	HeaderType      string
	HeaderTypeValue string
	Token           string
}

AuthorizationTypeStruct represents struct of Authorization Type

type ClientCache

type ClientCache struct {
	ID           int            `json:"-" db:"id"`
	URL          string         `json:"url" db:"url"`
	Method       string         `json:"method" db:"method"`
	ClientID     int            `json:"clientId" db:"clientId"`
	ClientName   string         `json:"clientName" db:"clientName"`
	Response     types.Metadata `json:"response" db:"response"`
	LastAccessed time.Time      `json:"lastAccessed" db:"lastAccessed"`
}

ClientCache object of ClientCache to reflect the url-to-cache data for response purpose swagger:model

type ClientCacheService

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

ClientCacheService implements the ClientCache repository service interface

func NewClientCacheService

func NewClientCacheService(
	clientCacheRepository ClientCacheStorage,
	urlToCache URLToCacheServiceInterface,
) *ClientCacheService

NewClientCacheService creates new ClientCache service

func (*ClientCacheService) CountClientCache

func (s *ClientCacheService) CountClientCache(ctx *context.Context, params *FindAllClientCachesParams) (int, *types.Error)

CountClientCache get list of ClientCache

func (*ClientCacheService) CreateClientCache

func (s *ClientCacheService) CreateClientCache(ctx *context.Context, params *CreateClientCacheParams) (*ClientCache, *types.Error)

CreateClientCache creates a new ClientCache

func (*ClientCacheService) DeleteClientCache

func (s *ClientCacheService) DeleteClientCache(ctx *context.Context, clientCacheID int) *types.Error

DeleteClientCache delete ClientCache

func (*ClientCacheService) GetClientCache

func (s *ClientCacheService) GetClientCache(ctx *context.Context, clientCacheID int) (*ClientCache, *types.Error)

GetClientCache get ClientCache by its id

func (*ClientCacheService) GetClientCacheByURL

func (s *ClientCacheService) GetClientCacheByURL(ctx *context.Context, params *GetClientCacheByURLParams) (*ClientCache, *types.Error)

GetClientCacheByURL get ClientCache by url

func (*ClientCacheService) IsClientNeedToBeCache

func (s *ClientCacheService) IsClientNeedToBeCache(ctx *context.Context, url string, method string) (bool, *types.Error)

IsClientNeedToBeCache a function to validate whether client request needs to be cache

func (*ClientCacheService) ListClientCaches

func (s *ClientCacheService) ListClientCaches(ctx *context.Context, params *FindAllClientCachesParams) ([]*ClientCache, *types.Error)

ListClientCaches get list of ClientCache

func (*ClientCacheService) UpdateClientCache

func (s *ClientCacheService) UpdateClientCache(ctx *context.Context, clientCacheID int, params *UpdateClientCacheParams) (*ClientCache, *types.Error)

UpdateClientCache updates a ClientCache

type ClientCacheServiceInterface

type ClientCacheServiceInterface interface {
	CountClientCache(ctx *context.Context, params *FindAllClientCachesParams) (int, *types.Error)
	GetClientCache(ctx *context.Context, clientCacheID int) (*ClientCache, *types.Error)
	ListClientCaches(ctx *context.Context, params *FindAllClientCachesParams) ([]*ClientCache, *types.Error)
	CreateClientCache(ctx *context.Context, params *CreateClientCacheParams) (*ClientCache, *types.Error)
	UpdateClientCache(ctx *context.Context, clientCache int, params *UpdateClientCacheParams) (*ClientCache, *types.Error)
	DeleteClientCache(ctx *context.Context, clientCacheID int) *types.Error
	IsClientNeedToBeCache(ctx *context.Context, url string, method string) (bool, *types.Error)
	GetClientCacheByURL(ctx *context.Context, params *GetClientCacheByURLParams) (*ClientCache, *types.Error)
}

ClientCacheServiceInterface represents the interface for servicing ClientCache object

type ClientCacheStorage

type ClientCacheStorage interface {
	FindByID(ctx *context.Context, clientCacheID int) (*ClientCache, *types.Error)
	FindByURL(ctx *context.Context, url string, method string, bufferedTime *int) (*ClientCache, *types.Error)
	FindAll(ctx *context.Context, params *FindAllClientCachesParams) ([]*ClientCache, *types.Error)
	Insert(ctx *context.Context, clientCache *ClientCache) (*ClientCache, *types.Error)
	Update(ctx *context.Context, clientCache *ClientCache) (*ClientCache, *types.Error)
	Delete(ctx *context.Context, clientCache *ClientCache) *types.Error
}

ClientCacheStorage represents the interface for manage ClientCache object

type ClientRequest

type ClientRequest struct {
	Client  *HTTPClient
	Request *ClientRequestLog
}

ClientRequest encapsulated object of http client and client request log for acknowledge used

type ClientRequestLog

type ClientRequestLog struct {
	ID             int            `json:"id" db:"id"`
	ClientID       int            `json:"clientId" db:"clientId"`
	ClientType     string         `json:"clientType" db:"clientType"`
	TransactionID  int            `json:"transactionId" db:"transactionId"`
	Method         string         `json:"method" db:"method"`
	URL            string         `json:"url" db:"url"`
	Header         string         `json:"header" db:"header"`
	Request        types.Metadata `json:"request" db:"request"`
	Status         string         `json:"status" db:"status"`
	HTTPStatusCode int            `json:"httpStatusCode" db:"httpStatusCode"`
	ReferenceID    int            `json:"referenceId" db:"referenceId"`
	Response       string         `json:"response" db:"response"`
	CURL           string         `json:"curl" db:"curl"`
}

ClientRequestLog object of client request log (log of request to external client) swagger:model

type ClientRequestLogStorage

type ClientRequestLogStorage interface {
	FindAll(ctx *context.Context, params *FindAllClientRequestLogs) []*ClientRequestLog
	FindByID(ctx *context.Context, clientRequestLogID int) *ClientRequestLog
	Insert(ctx *context.Context, clientRequestLog *ClientRequestLog) *ClientRequestLog
	Update(ctx *context.Context, clientRequestLog *ClientRequestLog) *ClientRequestLog
	Delete(ctx *context.Context, clientRequestLogID int)
}

ClientRequestLogStorage represents the interface for manage client request log object

type CreateClientCacheParams

type CreateClientCacheParams struct {
	URL          string         `json:"baseUrl"`
	Method       string         `json:"method"`
	ClientID     int            `json:"clientId"`
	ClientName   string         `json:"clientName"`
	Response     types.Metadata `json:"response"`
	LastAccessed time.Time      `json:"lastAccessed"`
}

CreateClientCacheParams represent the http request data for create ClientCache swagger:model

type CreateURLToCacheParams

type CreateURLToCacheParams struct {
	BaseURL      string `json:"baseUrl"`
	Method       string `json:"method"`
	ClientID     int    `json:"clientId"`
	ClientName   string `json:"clientName"`
	BufferedTime int    `json:"bufferedTime"`
	IsBlocked    bool   `json:"isBlocked"`
}

CreateURLToCacheParams represent the http request data for create URLToCache swagger:model

type FindAllAcknowledgeRequests

type FindAllAcknowledgeRequests struct {
	Search string `json:"search"`
	Page   int    `json:"page"`
	Limit  int    `json:"limit"`
}

FindAllAcknowledgeRequests represents params to get All acknowledge request swagger:model

type FindAllClientCachesParams

type FindAllClientCachesParams struct {
	Search     string `json:"search"`
	Page       int    `json:"page"`
	Limit      int    `json:"limit"`
	Method     string `json:"method"`
	ClientName string `json:"clientName"`
}

FindAllClientCachesParams represents params to get ListClientCaches swagger:model

type FindAllClientRequestLogs

type FindAllClientRequestLogs struct {
	Search string `json:"search"`
	Page   int    `json:"page"`
	Limit  int    `json:"limit"`
}

FindAllClientRequestLogs represents params to get All Client Request Logs swagger:model

type FindAllURLToCachesParams

type FindAllURLToCachesParams struct {
	Search       string `json:"search"`
	Page         int    `json:"page"`
	Limit        int    `json:"limit"`
	BufferedTime int    `json:"bufferedTime"`
	IsBlocked    bool   `json:"isBlocked"`
	Method       string `json:"method"`
	ClientName   string `json:"clientName"`
}

FindAllURLToCachesParams represents params to get ListURLToCaches swagger:model

type GenericHTTPClient

type GenericHTTPClient interface {
	Do(req *http.Request) (string, *ResponseError)
	CallClient(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCaching(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCachingInRedis(ctx *context.Context, durationInSecond int, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCachingInRedisWithDifferentKey(ctx *context.Context, durationInSecond int, path string, pathToBeStoredAsKey string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCircuitBreaker(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithoutLog(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithBaseURLGiven(ctx *context.Context, url string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCustomizedError(ctx *context.Context, path string, method Method, queryParams interface{}, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithCustomizedErrorAndCaching(ctx *context.Context, path string, method Method, queryParams interface{}, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError
	CallClientWithRequestInBytes(ctx *context.Context, path string, method Method, request []byte, result interface{}) *ResponseError
	AddAuthentication(ctx *context.Context, authorizationType AuthorizationType)
}

GenericHTTPClient represents an interface to generalize an object to implement HTTPClient

type GetClientCacheByURLParams

type GetClientCacheByURLParams struct {
	URL      string `json:"url"`
	Method   string `json:"method"`
	IsActive bool   `json:"isActive"`
}

GetClientCacheByURLParams params to collect client cache by url

type HTTPClient

type HTTPClient struct {
	APIURL             string
	HTTPClient         *http.Client
	MaxNetworkRetries  int
	UseNormalSleep     bool
	AuthorizationTypes []AuthorizationType
	ClientName         string
	// contains filtered or unexported fields
}

HTTPClient represents the service http client

func NewHTTPClient

func NewHTTPClient(
	config HTTPClient,
	clientRequestLogStorage ClientRequestLogStorage,
	acknowledgeRequestService AcknowledgeRequestServiceInterface,
	clientCacheService ClientCacheServiceInterface,
	redisClient *redis.Client,
) *HTTPClient

NewHTTPClient creates the new http client

func (*HTTPClient) AddAuthentication

func (c *HTTPClient) AddAuthentication(ctx *context.Context, authorizationType AuthorizationType)

AddAuthentication do add authentication

func (*HTTPClient) CallClient

func (c *HTTPClient) CallClient(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClient do call client

func (*HTTPClient) CallClientWithBaseURLGiven

func (c *HTTPClient) CallClientWithBaseURLGiven(ctx *context.Context, url string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithBaseURLGiven do call client with base url given

func (*HTTPClient) CallClientWithCaching

func (c *HTTPClient) CallClientWithCaching(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCaching do call client if client is unavailable try to collect response from cache when the time is still fulfill

func (*HTTPClient) CallClientWithCachingInRedis

func (c *HTTPClient) CallClientWithCachingInRedis(ctx *context.Context, durationInSecond int, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCachingInRedis call client with caching in redis

func (*HTTPClient) CallClientWithCachingInRedisWithDifferentKey

func (c *HTTPClient) CallClientWithCachingInRedisWithDifferentKey(ctx *context.Context, durationInSecond int, path string, pathToBeStoredAsKey string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCachingInRedisWithDifferentKey call client with caching in redis with different key

func (*HTTPClient) CallClientWithCircuitBreaker

func (c *HTTPClient) CallClientWithCircuitBreaker(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCircuitBreaker do call client with circuit breaker (async)

func (*HTTPClient) CallClientWithCustomizedError

func (c *HTTPClient) CallClientWithCustomizedError(ctx *context.Context, path string, method Method, queryParams interface{}, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCustomizedError do call client with customized error

func (*HTTPClient) CallClientWithCustomizedErrorAndCaching

func (c *HTTPClient) CallClientWithCustomizedErrorAndCaching(ctx *context.Context, path string, method Method, queryParams interface{}, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithCustomizedErrorAndCaching do call client with customized error and caching

func (*HTTPClient) CallClientWithRequestInBytes

func (c *HTTPClient) CallClientWithRequestInBytes(ctx *context.Context, path string, method Method, request []byte, result interface{}) *ResponseError

CallClientWithRequestInBytes do call client with request in bytes and omit acknowledge process - specific case for consumer

func (*HTTPClient) CallClientWithoutLog

func (c *HTTPClient) CallClientWithoutLog(ctx *context.Context, path string, method Method, request interface{}, result interface{}, isAcknowledgeNeeded bool) *ResponseError

CallClientWithoutLog do call client without log

func (*HTTPClient) Do

func (c *HTTPClient) Do(req *http.Request) (string, *ResponseError)

Do calls the api http request and parse the response into v

type Method

type Method string

Method represents the enum for http call method

const (
	POST   Method = "POST"
	PUT    Method = "PUT"
	DELETE Method = "DELETE"
	GET    Method = "GET"
	PATCH  Method = "PATCH"
)

Enum value for http call method

type ResponseError

type ResponseError struct {
	// General Error Response
	Code       string         `json:"code"`
	Message    string         `json:"message"`
	Fields     types.Metadata `json:"-"`
	StatusCode int            `json:"statusCode"`
	Error      error          `json:"error"`

	// Error Response for Anteraja
	Status int    `json:"status"`
	Info   string `json:"info"`
}

ResponseError represents struct of Authorization Type

type URLToCache

type URLToCache struct {
	ID           int    `json:"-" db:"id"`
	BaseURL      string `json:"baseUrl" db:"baseUrl"`
	Method       string `json:"method" db:"method"`
	ClientID     int    `json:"clientId" db:"clientId"`
	ClientName   string `json:"clientName" db:"clientName"`
	BufferedTime int    `json:"bufferedTime" db:"bufferedTime"`
	IsBlocked    bool   `json:"isBlocked" db:"isBlocked"`
}

URLToCache object of URLToCache to reflect the url-to-cache data for response purpose swagger:model

type URLToCacheService

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

URLToCacheService implements the URLToCache repository service interface

func NewURLToCacheService

func NewURLToCacheService(
	urlToCacheRepository URLToCacheStorage,
) *URLToCacheService

NewURLToCacheService creates new URLToCache service

func (*URLToCacheService) CountURLToCache

func (s *URLToCacheService) CountURLToCache(ctx *context.Context, params *FindAllURLToCachesParams) (int, *types.Error)

CountURLToCache get list of URLToCache

func (*URLToCacheService) CreateURLToCache

func (s *URLToCacheService) CreateURLToCache(ctx *context.Context, params *CreateURLToCacheParams) (*URLToCache, *types.Error)

CreateURLToCache creates a new URLToCache

func (*URLToCacheService) DeleteURLToCache

func (s *URLToCacheService) DeleteURLToCache(ctx *context.Context, urlToCacheID int) *types.Error

DeleteURLToCache delete URLToCache

func (*URLToCacheService) GetURLToCache

func (s *URLToCacheService) GetURLToCache(ctx *context.Context, urlToCacheID int) (*URLToCache, *types.Error)

GetURLToCache get URLToCache by its id

func (*URLToCacheService) GetURLToCacheByURL

func (s *URLToCacheService) GetURLToCacheByURL(ctx *context.Context, url string, method string) (*URLToCache, *types.Error)

GetURLToCacheByURL get URLToCache by its id

func (*URLToCacheService) ListURLToCaches

func (s *URLToCacheService) ListURLToCaches(ctx *context.Context, params *FindAllURLToCachesParams) ([]*URLToCache, *types.Error)

ListURLToCaches get list of URLToCache

func (*URLToCacheService) UpdateURLToCache

func (s *URLToCacheService) UpdateURLToCache(ctx *context.Context, urlToCacheID int, params *UpdateURLToCacheParams) (*URLToCache, *types.Error)

UpdateURLToCache updates a URLToCache

type URLToCacheServiceInterface

type URLToCacheServiceInterface interface {
	CountURLToCache(ctx *context.Context, params *FindAllURLToCachesParams) (int, *types.Error)
	GetURLToCache(ctx *context.Context, couponID int) (*URLToCache, *types.Error)
	GetURLToCacheByURL(ctx *context.Context, url string, method string) (*URLToCache, *types.Error)
	ListURLToCaches(ctx *context.Context, params *FindAllURLToCachesParams) ([]*URLToCache, *types.Error)
	CreateURLToCache(ctx *context.Context, params *CreateURLToCacheParams) (*URLToCache, *types.Error)
	UpdateURLToCache(ctx *context.Context, urlToCache int, params *UpdateURLToCacheParams) (*URLToCache, *types.Error)
	DeleteURLToCache(ctx *context.Context, urlToCacheID int) *types.Error
}

URLToCacheServiceInterface represents the interface for servicing URLToCache object

type URLToCacheStorage

type URLToCacheStorage interface {
	FindByID(ctx *context.Context, urlToCacheID int) (*URLToCache, *types.Error)
	FindByURL(ctx *context.Context, url string, method string) (*URLToCache, *types.Error)
	FindAll(ctx *context.Context, params *FindAllURLToCachesParams) ([]*URLToCache, *types.Error)
	Insert(ctx *context.Context, urlToCache *URLToCache) (*URLToCache, *types.Error)
	Update(ctx *context.Context, urlToCache *URLToCache) (*URLToCache, *types.Error)
	Delete(ctx *context.Context, urlToCache *URLToCache) *types.Error
}

URLToCacheStorage represents the interface for manage URLToCache object

type UpdateClientCacheParams

type UpdateClientCacheParams struct {
	URL          string         `json:"baseUrl"`
	Method       string         `json:"method"`
	ClientID     int            `json:"clientId"`
	ClientName   string         `json:"clientName"`
	Response     types.Metadata `json:"response"`
	LastAccessed time.Time      `json:"lastAccessed"`
}

UpdateClientCacheParams represent the http request data for update ClientCache swagger:model

type UpdateURLToCacheParams

type UpdateURLToCacheParams struct {
	BaseURL      string `json:"baseUrl"`
	Method       string `json:"method"`
	ClientID     int    `json:"clientId"`
	ClientName   string `json:"clientName"`
	BufferedTime int    `json:"bufferedTime"`
	IsBlocked    bool   `json:"isBlocked"`
}

UpdateURLToCacheParams represent the http request data for update URLToCache swagger:model

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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