stdutil

package module
v0.0.0-...-f8c4096 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 26 Imported by: 1

README

stdutil

Standard utilities for NarsilWorks

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

View Source
const REQUEST_MODIFIED string = "15112023"
View Source
const REQUEST_VERSION string = "1.0.0.0"

Variables

View Source
var (
	ErrRVNoBody = errors.New(`the request has no payload`)
)

Errors

Functions

func AnyToString

func AnyToString(value interface{}) string

AnyToString converts any variable to string

func BuildAccessToken

func BuildAccessToken(header *map[string]interface{}, claims *map[string]interface{}, secretkey string) string

BuildAccessToken builds a JWT token

func BuildEvent

func BuildEvent(subject EventSubject, eventVerb string, data interface{}, index int64) ([]byte, error)

BuildEvent builds an event based on the inputs

func BuildSeries

func BuildSeries(series int, opt SeriesOptions) string

BuildSeries builds series based on options

func DecodeCommand deprecated

func DecodeCommand(encoded string) string

DecodeCommand decodes an encrypted and base64-encoded text for the receiving page

It uses the library key to decrypt the string after the input has been decoded from base64

Deprecated: Use the EncodeText and DecodeText functions with a 32-bit application-defined key

func DecodeText

func DecodeText(encoded string, key []byte) string

DecodeText decodes an encypted base64-encoded text with a key and returns a decrypted string

func Decrypt

func Decrypt(ciphertext []byte, key []byte) ([]byte, error)

Decrypt - decrypt a string using AES

func Elem

func Elem[T any](array *[]T, index int, exists *bool) T

Elem returns the element of an array as specified by the index

If the index exceeds the length of an array, it will return a non-nil value of the type. To monitor if the element exists, define a boolean value in the exists parameter

This function requires version 1.18+

func ElemPtr

func ElemPtr[T any](array *[]T, index int, exists *bool) *T

ElemPtr returns a pointer to the element of an array as specified by the index

If the index exceeds the length of an array, it will return a non-nil value of the type. To monitor if the element exists, define a boolean value in the exists parameter

This function requires version 1.18+

func EncodeCommand deprecated

func EncodeCommand(command string) string

EncodeCommand encodes a command to be decoded by the receiving page

It uses the library key to encrypt the string and later encoded with base64

Deprecated: Use the EncodeText and DecodeText functions with a 32-bit application-defined key

func EncodeText

func EncodeText(plainText string, key []byte) string

EncodeText encodes plain text with a key and returns an encrypted and base64-encoded string

func Encrypt

func Encrypt(plaintext []byte, key []byte) ([]byte, error)

Encrypt - encrypt a string using AES

func ExecuteAPI

func ExecuteAPI(method string, endPoint string, payload []byte, compressed bool, header map[string]string, timeOut int) ([]byte, error)

ExecuteAPI wraps http operation that change or read data and returns a byte array

func GenerateAlpha

func GenerateAlpha(length int, lower bool) string

GenerateAlpha generates a random text that uses the 26 letters of the alphabet

func GenerateFull

func GenerateFull(length int) string

GenerateFull generates a random text that uses all letters of the alphabet, in both cases including numbers

func GenerateSeries

func GenerateSeries(length int) string

GenerateSeries generates random numbers

func GenerateText

func GenerateText(length int) string

GenerateText generates a random text that uses all letters of the alphabet, in both cases not including numbers

func GetZero

func GetZero[T FieldTypeConstraint]() T

GetZero gets the zero value of the types defined as constraints.Ordered, time.Time and shopspring/decimal

This function requires version 1.18+

func In

func In[T comparable](seek T, list ...T) bool

In checks if the seek parameter is in the list parameter

func Interpolate

func Interpolate(base string, keyValues NameValues) (string, []interface{})

Interpolate interpolates string with the name value pairs

func IsEmpty

func IsEmpty[T FieldTypeConstraint](value *T) bool

IsNullOrEmpty checks for emptiness of a pointer variable ignoring nullity Currently supported data types are the ones in the constraints.Ordered, time.Time, bool and shopspring/decimal

This function requires version 1.18+

func IsNullOrEmpty

func IsNullOrEmpty[T FieldTypeConstraint](value *T) bool

IsNullOrEmpty checks for nullity and emptiness of a pointer variable Currently supported data types are the ones in the constraints.Ordered, time.Time, bool and shopspring/decimal

This function requires version 1.18+

func IsStringNumeric

func IsStringNumeric(value *string) error

IsStringNumeric checks if a string is numeric

func Itos

func Itos(value interface{}) string

Itos is a shortcut to AnyToString. I means Interface

func NameValueGet

func NameValueGet[T constraints.Ordered | bool](nvs NameValues, name string) T

NameValueGet gets the value from the collection of NameValues by name

This function requires version 1.18+

func NameValueGetPtr

func NameValueGetPtr[T constraints.Ordered | bool](nvs NameValues, name string) *T

NameValueGetPtr gets the value from the collection of NameValues by name as pointer

This function requires version 1.18+

func NameValuesToInterfaceArray

func NameValuesToInterfaceArray(values NameValues) []interface{}

NameValuesToInterfaceArray converts name values to interface array

func New

func New[T FieldTypeConstraint](value T) *T

New initializes a variable and returns a pointer of its type Currently supported data types are the ones in the constraints.Ordered, time.Time, bool and shopspring/decimal

This function requires version 1.18+

func NonNullComp

func NonNullComp[T FieldTypeConstraint](param1 *T, param2 *T) int

NonNullComp compares two parameters when both are not nil. When one or both of the parameters is nil, the function returns -1 When the parameters are equal, the function returns 0. Else it returns 1

This function requires version 1.18+

func Null

func Null[T any](testValue any, defaultValue any) T

Null accepts a value to test and the default value if it fails. It returns a non-pointer value of T.

This function requires version 1.18+

func NullPtr

func NullPtr[T any](testValue any, defaultValue any) *T

NullPtr accepts a value to test and the default value if it fails. It returns a pointer value of T.

This function requires version 1.18+

func ParseRouteVars

func ParseRouteVars(r *http.Request) (Command []string, Key string)

ParseRouteVars parses custom routes from a mux handler

func SafeMapRead

func SafeMapRead[T any](ptrMap *map[string]T, key string, rw *sync.RWMutex) T

SafeMapRead allows reading maps by locking it, preventing the library from crashing

func SafeMapWrite

func SafeMapWrite[T any](ptrMap *map[string]T, key string, value T, rw *sync.RWMutex) bool

SafeMapWrite allows writing to maps by locking, preventing the library from crashing

func SetRequestTimeout

func SetRequestTimeout(timeout int)

SetRequestTimeOut sets the new timeout value

func StripEndingForwardSlash

func StripEndingForwardSlash(value string) string

StripEndingForwardSlash removes the ending forward slash of a string

func StripLeading

func StripLeading(value string, offset int) string

StripLeading strips string of leading characters by an offset

func StripTrailing

func StripTrailing(value string, length int) string

StripTrailing strips string of trailing characters after the length

func ToInterfaceArray

func ToInterfaceArray[T FieldTypeConstraint](values T) []interface{}

ToInterfaceArray converts a value to interface array

This function requires version 1.18+

func Val

func Val[T FieldTypeConstraint](value *T) T

Val gets the value of a pointer in order Currently supported data types are the ones in the constraints.Ordered, time.Time, bool and shopspring/decimal

This function requires version 1.18+

func ValidateDecimal

func ValidateDecimal(value *ssd.Decimal, opts *DecimalValidationOptions) error

ValidateDecimal validates a decimal input against decimal validation options

func ValidateEmail

func ValidateEmail(email *string) error

ValidateEmail - validate an e-mail address

func ValidateNumeric

func ValidateNumeric[T NumericConstraint](value *T, opts *NumericValidationOptions[T]) error

ValidateNumeric validates a numeric input against numeric validation options

func ValidateString

func ValidateString(value *string, opts *StringValidationOptions) error

ValidateString validates an input string against the string validation options

func ValidateTime

func ValidateTime(value *time.Time, opts *TimeValidationOptions) error

ValidateTime validates an input time against the time validation options

Types

type CustomPayload

type CustomPayload struct {
	jwt.Payload
	UserName      string `json:"usr,omitempty"` // Username payload for JWT
	Domain        string `json:"dom,omitempty"` // Domain payload for JWT
	ApplicationID string `json:"app,omitempty"` // Application payload for JWT
	DeviceID      string `json:"dev,omitempty"` // Device id payload for JWT
	TenantID      string `json:"tnt,omitempty"` // Tenant id payload for JWT
}

CustomPayload - payload for JWT

type CustomVars

type CustomVars struct {
	Command        []string   // Commands represents the sub-paths in the URL request
	Key            string     // The key of the the request
	QueryString    NameValues // The query string values of the URL request
	HasQueryString bool       // Indicates that the URL request has a query string
	FormData       NameValues // The form values associated with the URL request, usually appear when the method is POST and PUT
	HasFormData    bool       // Indicates that the URL request has form data
	IsMultipart    bool       // Indicates that the URL request is a multi part request
	DecodedCommand NameValues // Decoded commands from an encrypted values represented by q query string
}

CustomVars - command struct

func (CustomVars) FirstCommand

func (cv CustomVars) FirstCommand() string

FirstCommand - get first command from route

func (CustomVars) GetCommand

func (cv CustomVars) GetCommand(index uint) (exists bool, value string)

GetCommand - get command by index

func (CustomVars) LastCommand

func (cv CustomVars) LastCommand() string

LastCommand - get third command from route

func (CustomVars) SecondCommand

func (cv CustomVars) SecondCommand() string

SecondCommand - get second command from route

func (CustomVars) ThirdCommand

func (cv CustomVars) ThirdCommand() string

ThirdCommand - get third command from route

type DecimalValidationOptions

type DecimalValidationOptions struct {
	Null     bool         // Allow null. Default: false, will raise an error if the decimal is null
	Empty    bool         // Allow zero decimal. Default: false, will raise an error if the decimal is zero
	Min      *ssd.Decimal // Minimum decimal value. Default: nil
	Max      *ssd.Decimal // Maximum decimal value. Default: nil
	Extended []func(value *ssd.Decimal) error
}

type Event

type Event struct {
	Index   int64       `json:"index,omitempty"`   // Optional. Index of this data to return to later
	Subject string      `json:"subject,omitempty"` // Subject of the event
	Data    interface{} `json:"data,omitempty"`    // Data of the event
}

Event contains the address and the event data

type EventSubject

type EventSubject struct {
	Application string // Application. This would form as the first segment
	Service     string // Service. This would form as the second segment
	Module      string // Module. This would form as the last segment
}

EventSubject is a struct to describe the subject event

func GetEventModuleMatch

func GetEventModuleMatch(module string, evtChans []EventSubject) *EventSubject

GetEventModuleMatch seeks the list of events by module

func GetEventSubjectMatch

func GetEventSubjectMatch(subject string, evtChans []EventSubject) *EventSubject

GetEventSubjectMatch seeks the list of event by subject

func NewEventSubjectBase

func NewEventSubjectBase(application, service, module string) EventSubject

NewEventSubjectBase properly creates a new event base.

func (EventSubject) ToString

func (ec EventSubject) ToString(eventVerb *string) string

ToString converts an EventSubject to a readable string

type FieldTypeConstraint

type FieldTypeConstraint interface {
	constraints.Ordered | time.Time | ssd.Decimal | bool | byte
}

type JWTInfo

type JWTInfo struct {
	ApplicationID string   // Application ID from the JWT token
	Audience      []string // Audience intended by the token
	DeviceID      string   // The device id where the token came from
	Domain        string   // The application domain that the token is intended for
	Raw           string   // Raw JWT token
	TenantID      string   // Tenant ID from the JWT token
	UserName      string   // User account authenticated and produced the token
	Valid         bool     // Indicates that the request has a valid JWT token
}

JWTInfo contains the information about JWT

func ParseJWT

func ParseJWT(token, secretKey string, validateTimes bool) (*JWTInfo, error)

ParseJWT validates, parses JWT and returns information

func ValidateJWT

func ValidateJWT(r *http.Request, secretKey string, validateTimes bool) (*JWTInfo, error)

ValidateJWT validates JWT and returns information

type NameValue

type NameValue[T any] struct {
	Name  string `json:"name,omitempty"`
	Value T      `json:"value,omitempty"`
}

type NameValues

type NameValues struct {
	Pair map[string]any
	// contains filtered or unexported fields
}

NameValues - a struct to manage value structs

func ParseQueryString

func ParseQueryString(qs *string) NameValues

ParseQueryString parses the query string into a column value

func SortByKey

func SortByKey(values *NameValues, keyOrder *[]string) NameValues

SortByKey reorders keys and values based on a keyOrder array sequence

func (*NameValues) Bool

func (nvp *NameValues) Bool(name string) (bool, bool)

Bool returns the name value as boolean. It automatically convers 'true', 'yes', '1', '-1' and 'on' to boolean The second argument returns the existence.

func (*NameValues) Bools

func (nvp *NameValues) Bools(name string) []bool

Bools returns the values as a boolean array

func (*NameValues) Exists

func (nvp *NameValues) Exists(name string) bool

Exists checks if the key or name exists. It returns the index of the element if found, -1 if not found.

func (*NameValues) Float64

func (nvp *NameValues) Float64(name string) (float64, bool)

Float64 returns the name value as float64. The second argument returns the existence.

func (*NameValues) Float64s

func (nvp *NameValues) Float64s(name string) []float64

Float64s returns the values as a float64 array

func (*NameValues) Int

func (nvp *NameValues) Int(name string) (int, bool)

Int returns the name value as int. The second argument returns the existence.

func (*NameValues) Int64

func (nvp *NameValues) Int64(name string) (int64, bool)

Int64 returns the name value as int64. The second argument returns the existence.

func (*NameValues) Int64s

func (nvp *NameValues) Int64s(name string) []int64

Int64s returns the values as an int64 array

func (*NameValues) Interpolate

func (nvp *NameValues) Interpolate(base string) (string, []interface{})

Interpolate - interpolate string with values from with base string

func (*NameValues) Ints

func (nvp *NameValues) Ints(name string) []int

Ints returns the values as an int array

func (*NameValues) Plain

func (nvp *NameValues) Plain(name string) (interface{}, bool)

Plain returns the name value as interface{}. The second argument returns the existence.

func (*NameValues) PtrBool

func (nvp *NameValues) PtrBool(name string) (*bool, bool)

PtrBool returns the name value as pointer to bool. The second argument returns the existence.

func (*NameValues) PtrFloat64

func (nvp *NameValues) PtrFloat64(name string) (*float64, bool)

PtrFloat64 returns the name value as pointer to int64. The second argument returns the existence.

func (*NameValues) PtrInt

func (nvp *NameValues) PtrInt(name string) (*int, bool)

PtrInt returns the name value as pointer to int. The second argument returns the existence.

func (*NameValues) PtrInt64

func (nvp *NameValues) PtrInt64(name string) (*int64, bool)

PtrInt64 returns the name value as pointer to int64. The second argument returns the existence.

func (*NameValues) PtrPlain

func (nvp *NameValues) PtrPlain(name string) (*interface{}, bool)

PtrPlain returns the name value as pointer to interface{}. The second argument returns the existence.

func (*NameValues) PtrString

func (nvp *NameValues) PtrString(name string) (*string, bool)

PtrString returns the name value as pointer to string. The second argument returns the existence.

func (*NameValues) SortByKey

func (nvp *NameValues) SortByKey(keyOrder *[]string) NameValues

SortByKey sort name values by key order array

func (*NameValues) String

func (nvp *NameValues) String(name string) (string, bool)

String returns the name value as string. The second argument returns the existence.

func (*NameValues) Strings

func (nvp *NameValues) Strings(name string) []string

Strings returns the values as a string array

func (*NameValues) ToInterfaceArray

func (nvp *NameValues) ToInterfaceArray() []interface{}

ToInterfaceArray - converts name values to interface array

type NumericConstraint

type NumericConstraint interface {
	constraints.Integer | constraints.Float
}

type NumericValidationOptions

type NumericValidationOptions[T NumericConstraint] struct {
	Null     bool // Allow null. Default: false, will raise an error if the time is null
	Empty    bool // Allow zero time Default: false, will raise an error if the time is zero
	Min      T    // Minimum time. Default: nil
	Max      T    // Maximum time. Default: nil
	Extended []func(value *T) error
}

type RequestVars

type RequestVars struct {
	Body      []byte            // The body of the request
	Cookies   map[string]string // Cookies included in the request
	HasBody   bool              // Indicates that the request has a body
	Method    string            // Method of the request
	Variables CustomVars        // Variables included in the request
	Token     *JWTInfo          // Access token
}

RequestVars - contains necessary request variables

func GetRequestVars

func GetRequestVars(r *http.Request, secretKey string, validateTimes bool) (RequestVars, error)

GetRequestVars requests variables and return JWT validation result

func GetRequestVarsOnly

func GetRequestVarsOnly(r *http.Request) RequestVars

GetRequestVarsOnly get request variables

func (*RequestVars) IsDelete

func (rv *RequestVars) IsDelete() bool

IsDelete is a shortcut method to check if the request is a DELETE

func (*RequestVars) IsGet

func (rv *RequestVars) IsGet() bool

IsGet - a shortcut method to check if the request is a GET

func (*RequestVars) IsHead

func (rv *RequestVars) IsHead() bool

IsHead is a shortcut method to check if the request is a HEAD

func (*RequestVars) IsJSONGood

func (rv *RequestVars) IsJSONGood(v interface{}) error

IsJSONGood checks if the request has body and attempts to marshal to Json

func (*RequestVars) IsOptions

func (rv *RequestVars) IsOptions() bool

IsOptions is a shortcut method to check if the request is OPTIONS

func (*RequestVars) IsPost

func (rv *RequestVars) IsPost() bool

IsPost is a shortcut method to check if the request is a POST

func (*RequestVars) IsPostOrPut

func (rv *RequestVars) IsPostOrPut() bool

IsPostOrPut is a shortcut method to check if the request is a POST or PUT

func (*RequestVars) IsPut

func (rv *RequestVars) IsPut() bool

IsPut is a shortcut method to check if the request is a PUT

type Result

type Result struct {
	Messages      []string     `json:"messages"`                // Accumulated messages as a result from Add methods. Do not append messages using append()
	Status        string       `json:"status"`                  // OK, ERROR, VALID or any status
	Operation     string       `json:"operation,omitempty"`     // Name of the operation / function that returned the result
	TaskID        *string      `json:"task_id,omitempty"`       // ID of the request and of the result
	WorkerID      *string      `json:"worker_id,omitempty"`     // ID of the worker that processed the data
	FocusControl  *string      `json:"focus_control,omitempty"` // Control to focus when error was activated
	Page          *int         `json:"page,omitempty"`          // Current Page
	PageCount     *int         `json:"page_count,omitempty"`    // Page Count
	PageSize      *int         `json:"page_size,omitempty"`     // Page Size
	Tag           *interface{} `json:"tag,omitempty"`           // Miscellaneous result
	MessagePrefix string       `json:"prefix,omitempty"`        // Prefix of the message to return
	// contains filtered or unexported fields
}

Result - standard result structure

func InitResult

func InitResult(args ...NameValue[string]) Result

InitResult - initialize result for API query. This is the recommended initialization of this object. The variadic arguments of std.NameValue data type will be intepreted as follows:

To set the initial status, set NameValue.Name to "status" and set NameValue.Value to a valid status if the value is not a valid status, it will be ignored */

To set a message prefix, set NameValue.Name to "prefix" and set NameValue.Value to a string value.

To add a message, set NameValue.Name to "message" and set NameValue.Value to a valid message. Depending on the current status (default is EXCEPTION), the message type is automatically set to that type

func (*Result) AddErr

func (r *Result) AddErr(err error) Result

AddErr - adds a real error and returns itself

func (*Result) AddError

func (r *Result) AddError(message string) Result

AddError adds an error message and returns itself

func (*Result) AddErrorf

func (r *Result) AddErrorf(format string, a ...interface{}) Result

AddErrorf adds a formatted error message and returns itself

func (*Result) AddInfo

func (r *Result) AddInfo(message string) Result

AddInfo adds an information message and returns itself

func (*Result) AddInfof

func (r *Result) AddInfof(format string, a ...interface{}) Result

AddInfof adds a formatted information message and returns itself

func (*Result) AddWarning

func (r *Result) AddWarning(message string) Result

AddWarning - adds a warning message and returns itself

func (*Result) AddWarningf

func (r *Result) AddWarningf(format string, a ...interface{}) Result

AddWarningf adds a formatted warning message and returns itself

func (*Result) AppendErr

func (r *Result) AppendErr(rs Result, err error) Result

AppendErr copies the messages of the Result parameter and append an error message

func (*Result) AppendError

func (r *Result) AppendError(rs Result, message string) Result

AppendError copies the messages of the Result parameter and append the current message

func (*Result) AppendErrorf

func (r *Result) AppendErrorf(rs Result, format string, a ...interface{}) Result

AppendErrorf copies the messages of the Result parameter and append a formatted error message

func (*Result) AppendInfo

func (r *Result) AppendInfo(rs Result, message string) Result

AppendInfo copies the messages of the Result parameter and append the current message

func (*Result) AppendInfof

func (r *Result) AppendInfof(rs Result, format string, a ...interface{}) Result

AppendInfof copies the messages of the Result parameter and append a formatted information message

func (*Result) AppendWarning

func (r *Result) AppendWarning(rs Result, message string) Result

AppendWarning copies the messages of the Result parameter and append the current message

func (*Result) AppendWarningf

func (r *Result) AppendWarningf(rs Result, format string, a ...interface{}) Result

AppendWarningf copies the messages of the Result parameter and append a formatted warning message

func (*Result) Error

func (r *Result) Error() bool

Error returns true if the status is EXCEPTION.

func (*Result) EventID

func (r *Result) EventID() string

EventID returns the past tense of Operation

func (*Result) Invalid

func (r *Result) Invalid() bool

Invalid returns true if the status is INVALID.

func (*Result) MessageManager

func (r *Result) MessageManager() *livenote.LiveNote

MessageManager returns the internal message manager

func (*Result) MessagesToString

func (r *Result) MessagesToString() string

ToString adds a formatted error message and returns itself

func (*Result) No

func (r *Result) No() bool

No returns true if the status is No.

func (*Result) OK

func (r *Result) OK() bool

OK returns true if the status is OK.

func (*Result) Return

func (r *Result) Return(status Status) Result

Return a status

func (*Result) RowsAffectedInfo

func (r *Result) RowsAffectedInfo(rowsaff int64)

RowsAffectedInfo - a function to simplify adding information for rows affected

func (*Result) SetPrefix

func (r *Result) SetPrefix(pfx string)

SetPrefix changes the prefix

func (*Result) Stuff

func (r *Result) Stuff(rs Result) Result

Stuff messages of a result. The Result messages may contain different types of message

func (*Result) Valid

func (r *Result) Valid() bool

Valid returns true if the status is VALID.

func (*Result) Yes

func (r *Result) Yes() bool

Yes returns true if the status is YES.

type ResultAny

type ResultAny[T any] struct {
	Result
	Data T `json:"data"`
}

ResultAny - a result structure with an empty interface

type ResultData

type ResultData struct {
	Result
	Data json.RawMessage `json:"data"`
}

ResultData - a result structure and a JSON raw message

func DeleteJson

func DeleteJson(endpoint string, headers map[string]string, rw *sync.RWMutex) ResultData

DeleteJson wraps http.Delete with custom result

func ExecuteJsonAPI

func ExecuteJsonAPI(method string, endPoint string, payload []byte, compressed bool, header map[string]string, timeOut int, rw *sync.RWMutex) (rd ResultData)

ExecuteJsonAPI wraps http operation that change or read data and returns a custom result

func GetJson

func GetJson(endpoint string, headers map[string]string, rw *sync.RWMutex) ResultData

GetJson wraps http.Get with custom result

func PatchJson

func PatchJson(endpoint string, payload []byte, gzipped bool, headers map[string]string, rw *sync.RWMutex) ResultData

PatchJson wraps http.Patch with custom result

func PostJson

func PostJson(endpoint string, payload []byte, gzipped bool, headers map[string]string, rw *sync.RWMutex) ResultData

PostJson wraps http.Post with custom result

func PutJson

func PutJson(endpoint string, payload []byte, gzipped bool, headers map[string]string, rw *sync.RWMutex) ResultData

PutJson wraps http.Put with custom result

type SeriesOptions

type SeriesOptions struct {
	Prefix string // Prefix of series
	Suffix string // Suffix of series
	Length int    // Fixed length of the series
}

type Status

type Status string

Status type

const (
	OK        Status = `OK`
	EXCEPTION Status = `EXCEPTION`
	VALID     Status = `VALID`
	INVALID   Status = `INVALID`
	YES       Status = `YES`
	NO        Status = `NO`
)

Status items

type StringValidationOptions

type StringValidationOptions struct {
	Empty    bool // Allow empty string. Default: false, will raise an error if the string is empty
	Null     bool // Allow null. Default: false, will raise an error if the string is null
	Min      int  // Minimum length. Default: 0
	Max      int  // Maximum length. Default: 0
	NoSpaces bool // Do not allow spaces in the string. Default: false. Setting to true will raise an error if the string has spaces
	Extended []func(value *string) error
}

type TimeValidationOptions

type TimeValidationOptions struct {
	Null     bool       // Allow null. Default: false, will raise an error if the time is null
	Empty    bool       // Allow zero time Default: false, will raise an error if the time is zero
	Min      *time.Time // Minimum time. Default: nil
	Max      *time.Time // Maximum time. Default: nil
	DateOnly bool       // Compare dates only. Default: false
	Extended []func(value *time.Time) error
}

Jump to

Keyboard shortcuts

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