Documentation
¶
Index ¶
- func CreateRequest(ctx context.Context, httpMethod string, baseUrl string, requestPath string, ...) (*http.Request, errors.Error)
- func CreateRequestWithRawData(ctx context.Context, httpMethod string, baseUrl string, requestPath string, ...) (*http.Request, errors.Error)
- func CreateRequestWithRawDataAndHeaders(ctx context.Context, httpMethod string, baseUrl string, requestPath string, ...) (*http.Request, errors.Error)
- func EncodeAndWriteResponse(i any, w *echo.Response, lc log.Logger) error
- func EncodeAndWriteYamlResponse(i any, w *echo.Response, lc log.Logger) error
- func FromContext(ctx context.Context, key string) string
- func GetRequest(ctx context.Context, returnValuePointer interface{}, baseUrl string, ...) errors.Error
- func ParseGetAllObjectsRequestQueryString(r *http.Request, maxOffSet, maxResultCount int) (offset int, limit int, labels []string, err errors.Error)
- func ParseGetLogsRequestQueryString(r *http.Request) (since int, until int, tail int, timestamps bool, err errors.Error)
- func ParseQueryStringToString(r *http.Request, queryStringKey string, defaultValue string) string
- func ParseStartEndRequestQueryString(r *http.Request) (start, end int64, err errors.Error)
- func PostRequestWithRawData(ctx context.Context, returnValuePointer any, baseUrl string, ...) errors.Error
- func PostRequestWithRawDataAndHeaders(ctx context.Context, returnValuePointer any, baseUrl string, ...) errors.Error
- func PutRequest(ctx context.Context, returnValuePointer any, baseUrl string, ...) errors.Error
- func SendRequest(ctx context.Context, req *http.Request, ...) ([]byte, errors.Error)
- func SendRequestReturningStatus(ctx context.Context, req *http.Request, ...) (int, []byte, errors.Error)
- func WriteDefaultHttpHeader(w http.ResponseWriter, ctx context.Context, statusCode int)
- func WriteErrorResponse(w *echo.Response, ctx context.Context, lc log.Logger, err errors.Error, ...) error
- func WriteHttpContentTypeHeader(w http.ResponseWriter, ctx context.Context, statusCode int, contentType string)
- type BaseResponse
- type BaseWithIdResponse
- type BaseWithTotalCountResponse
- type HTTPSender
- type Versionable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateRequest ¶ added in v2.0.1
func CreateRequestWithRawDataAndHeaders ¶ added in v2.0.23
func CreateRequestWithRawDataAndHeaders(ctx context.Context, httpMethod string, baseUrl string, requestPath string, requestParams url.Values, data any, headers map[string]string) (*http.Request, errors.Error)
CreateRequestWithRawDataAndHeaders creates a request with raw JSON data and adds the additional request headers.
func EncodeAndWriteResponse ¶
EncodeAndWriteResponse encodes data as JSON and writes it to the HTTP response.
func EncodeAndWriteYamlResponse ¶
EncodeAndWriteYamlResponse encodes data as YAML and writes it to the HTTP response.
func FromContext ¶
FromContext allows for the retrieval of the specified key's value from the supplied Context. If the value is not found, an empty string is returned.
func GetRequest ¶ added in v2.0.1
func GetRequest(ctx context.Context, returnValuePointer interface{}, baseUrl string, requestPath string, requestParams url.Values, authInjector interfaces.AuthenticationInjector) errors.Error
GetRequest makes the get request and return the body
func ParseGetAllObjectsRequestQueryString ¶
func ParseGetAllObjectsRequestQueryString(r *http.Request, maxOffSet, maxResultCount int) (offset int, limit int, labels []string, err errors.Error)
ParseGetAllObjectsRequestQueryString parses offset, limit, and labels from the query parameters. And check that the offset and limit values are within the valid range when needed.
func ParseGetLogsRequestQueryString ¶
func ParseGetLogsRequestQueryString(r *http.Request) (since int, until int, tail int, timestamps bool, err errors.Error)
ParseGetLogsRequestQueryString parses since, until, tail and timestamps from the query parameters.
func PostRequestWithRawData ¶ added in v2.0.23
func PostRequestWithRawData( ctx context.Context, returnValuePointer any, baseUrl string, requestPath string, requestParams url.Values, data any, authInjector interfaces.AuthenticationInjector) errors.Error
PostRequestWithRawData makes the post JSON request with raw data and return the body
func PostRequestWithRawDataAndHeaders ¶ added in v2.0.23
func PostRequestWithRawDataAndHeaders( ctx context.Context, returnValuePointer any, baseUrl string, requestPath string, requestParams url.Values, data any, authInjector interfaces.AuthenticationInjector, headers map[string]string) errors.Error
PostRequestWithRawDataAndHeaders makes the post JSON request with raw data and additional request headers, and returns the body
func PutRequest ¶
func PutRequest( ctx context.Context, returnValuePointer any, baseUrl string, requestPath string, requestParams url.Values, data any, authInjector interfaces.AuthenticationInjector) errors.Error
PutRequest makes the put JSON request and return the body
func SendRequest ¶
func SendRequest(ctx context.Context, req *http.Request, authInjector interfaces.AuthenticationInjector) ([]byte, errors.Error)
SendRequest will make a request with raw data to the specified URL. It returns the body as a byte array if successful and an error otherwise.
func SendRequestReturningStatus ¶ added in v2.0.23
func SendRequestReturningStatus(ctx context.Context, req *http.Request, authInjector interfaces.AuthenticationInjector) (int, []byte, errors.Error)
SendRequestReturningStatus behaves like SendRequest but also returns the HTTP status code, letting callers branch on an exact status (e.g. 204 vs other 2xx). The status code is 0 when the request could not be sent (no response received).
func WriteDefaultHttpHeader ¶
func WriteDefaultHttpHeader(w http.ResponseWriter, ctx context.Context, statusCode int)
func WriteErrorResponse ¶
func WriteErrorResponse(w *echo.Response, ctx context.Context, lc log.Logger, err errors.Error, apiVersion, requestId string) error
WriteErrorResponse writes Http header, encode error response with JSON format and writes to the HTTP response.
Types ¶
type BaseResponse ¶
type BaseResponse struct {
Versionable `json:",inline"`
RequestId string `json:"requestId,omitempty"`
Message string `json:"message,omitempty"`
StatusCode int `json:"statusCode"`
}
BaseResponse defines the base content for response DTOs (data transfer objects).
func NewBaseResponse ¶
func NewBaseResponse(apiVersion, requestId, message string, statusCode int) BaseResponse
type BaseWithIdResponse ¶ added in v2.0.12
type BaseWithIdResponse struct {
BaseResponse `json:",inline"`
Id string `json:"id"`
}
BaseWithIdResponse defines the base content for response DTOs (data transfer objects).
func NewBaseWithIdResponse ¶ added in v2.0.12
func NewBaseWithIdResponse(apiVersion, requestId, message string, statusCode int, id string) BaseWithIdResponse
type BaseWithTotalCountResponse ¶ added in v2.0.12
type BaseWithTotalCountResponse struct {
BaseResponse `json:",inline"`
TotalCount int64 `json:"totalCount"`
}
BaseWithTotalCountResponse defines the base content for response DTOs (data transfer objects).
func NewBaseWithTotalCountResponse ¶ added in v2.0.12
func NewBaseWithTotalCountResponse(apiVersion, requestId, message string, statusCode int, totalCount int64) BaseWithTotalCountResponse
type HTTPSender ¶
type HTTPSender interface {
// SetHTTPRequestHeaders sets up http request headers
SetHTTPRequestHeaders(httpRequestHeaders map[string]string)
// SetSecretData sets up http secret header
SetSecretData(name, valueKey, headerName, valuePrefix string)
// HTTPPost sends http POST request with data
HTTPPost(dic *di.Container, data any) errors.Error
}
HTTPSender is the interface for http requests
func NewHTTPSender ¶
func NewHTTPSender(url string, mimeType string) HTTPSender
NewHTTPSender creates, initializes and returns a new instance of HTTPSender
type Versionable ¶
type Versionable struct {
ApiVersion string `json:"apiVersion" validate:"required"`
}
Versionable shows the API version in DTOs
func NewVersionable ¶
func NewVersionable() Versionable