utils

package
v1.3.1-dev.18.0...-398431f Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeTimestamp

func MakeTimestamp() int64

MakeTimestamp returns the Unix timestamp in milliseconds

func ParseBodyToMap

func ParseBodyToMap(r *http.Request) (map[string]string, errors.EdgeX)

Parse the body of http request to a map[string]string. EdgeX error will be returned if any parsing error occurs.

func ParseGetAllObjectsRequestQueryString

func ParseGetAllObjectsRequestQueryString(r *http.Request, minOffset int, maxOffset int, minLimit int, maxLimit int) (offset int, limit int, labels []string, err errors.EdgeX)

ParseGetAllObjectsRequestQueryString parses offset, limit and labels from the query parameters. And use maximum and minimum to check whether the offset and limit are valid.

func ParsePathParamToInt

func ParsePathParamToInt(r *http.Request, pathKey string) (int, errors.EdgeX)

Parse the specified path parameter to an integer. EdgeX error will be returned if any parsing error occurs or specified path parameter is empty.

func ParseQueryStringToInt

func ParseQueryStringToInt(r *http.Request, queryStringKey string, defaultValue int, min int, max int) (int, errors.EdgeX)

Parse the specified query string key to an integer. If specified query string key is found more than once in the http request, only the first specified query string will be parsed and converted to an integer. If no specified query string key could be found in the http request, specified default value will be returned. EdgeX error will be returned if any parsing error occurs.

func ParseQueryStringToString

func ParseQueryStringToString(r *http.Request, queryStringKey string, defaultValue string) string

Parse the specified query string key to a string. If specified query string key is found more than once in the http request, only the first specified query string will be parsed and converted to a string. If no specified query string could be found, defaultValue will be returned.

func ParseQueryStringToStrings

func ParseQueryStringToStrings(r *http.Request, queryStringKey string, separator string) (stringArray []string)

Parse the specified query string key to an array of string. If specified query string key is found more than once in the http request, only the first specified query string will be parsed and converted to an array of string. The value of query string will be split into an array of string by the passing separator. If separator is passed in as an empty string, comma separator will be used.

func ParseTimeRangeOffsetLimit

func ParseTimeRangeOffsetLimit(r *http.Request, minOffset int, maxOffset int, minLimit int, maxLimit int) (start int, end int, offset int, limit int, edgexErr errors.EdgeX)

func SendRequestWithRESTAddress

func SendRequestWithRESTAddress(lc logger.LoggingClient, content string, contentType string, address models.RESTAddress) (res string, err errors.EdgeX)

SendRequestWithRESTAddress sends request with REST address

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, ctx context.Context, lc logger.LoggingClient, err errors.EdgeX, requestId string)

WriteErrorResponse writes Http header, encode error response with JSON format and writes to the HTTP response.

func WriteHttpHeader

func WriteHttpHeader(w http.ResponseWriter, ctx context.Context, statusCode int)

Types

This section is empty.

Jump to

Keyboard shortcuts

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