utils

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 19 Imported by: 1

README

utils

Documentation

Index

Constants

View Source
const (
	// ContentTypeApplicationANY const
	ContentTypeApplicationANY = "*/*"
	// ContentTypeApplicationJSON const
	ContentTypeApplicationJSON = "application/json"
	// ContentTypeApplicationXML const
	ContentTypeApplicationXML = "application/xml"
	// ContentTypeHeader const
	ContentTypeHeader = "Content-Type"
	// AuthorizationHeader const
	AuthorizationHeader = "Authorization"
	// BearerToken const
	BearerToken = "Bearer "
)

Variables

View Source
var HTTPStatusCodes = map[HTTPStatusCode]string{
	200: "The API request is successful.",
	201: "Request fulfilled for single record insertion.",
	202: "Request fulfilled for multiple records insertion.",
	204: "There is no content available for the request.",
	304: "The requested page has not been modified. In case \"If-Modified-Since\" header is used for GET APIs",
	400: "The request or the authentication considered is invalid.",
	401: "Invalid API key provided.",
	403: "No permission to do the operation.",
	404: "Invalid request.",
	405: "The specified method is not allowed.",
	413: "The server did not accept the request while uploading a file, since the limited file size has exceeded.",
	415: "The server did not accept the request while uploading a file, since the media/ file type is not supported.",
	429: "Number of API requests per minute/day has exceeded the limit.",
	500: "Generic error that is encountered due to an unexpected server error.",
}

HTTPStatusCodes is a map of possible HTTP Status Code and Messages

Functions

func Contains

func Contains(s []string, e string) bool

check if string slice contains a value

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func CreateKeyValuePairs

func CreateKeyValuePairs(m map[string]string) string

func CreateSQSUrlFromArn

func CreateSQSUrlFromArn(arn string) string

func ErrorToText

func ErrorToText(err GenericResponse) string

ErrorToText

func FileExists

func FileExists(filename string) bool

FileExists func

func GetHeaderWithPrefixAndDecode

func GetHeaderWithPrefixAndDecode(headerName string, prefix string, r *http.Request) (string, error)

func GetISO3361CodeCountry

func GetISO3361CodeCountry(country string) string

func GetISOCodeCountry added in v1.0.3

func GetISOCodeCountry(country string) string

func GetRequestBody

func GetRequestBody(request *http.Request) ([]byte, error)

GetRequestBody return array of byte from the request

func Getenv

func Getenv(key, fallback string) string

func Indirect

func Indirect(reflectValue reflect.Value) reflect.Value

func IndirectType

func IndirectType(reflectType reflect.Type) reflect.Type

func IsCustomType

func IsCustomType(t reflect.Type) bool

isCustomType tester

func IsNativeKind

func IsNativeKind(v reflect.Kind) bool

func IsNil

func IsNil(i interface{}) bool

func IsPtrType

func IsPtrType(t reflect.Type) bool

IsPtrType tester

func IsPtrValue

func IsPtrValue(t reflect.Value) bool

IsPtrValue tester

func IsTimeType

func IsTimeType(t reflect.Type) bool

is time.Time type

func IsValidGUID

func IsValidGUID(guid string) bool

func JsonIt

func JsonIt(a interface{}) string

func Ptr

func Ptr(v reflect.Value) reflect.Value

ptr wraps the given value with pointer: V => *V, *V => **V, etc.

func ResolveStatus

func ResolveStatus(r *http.Response) string

func ResponseWriterJSON

func ResponseWriterJSON(writer http.ResponseWriter, response interface{})

ResponseWriterJSON function

func ResponseWriterTextHtml

func ResponseWriterTextHtml(writer http.ResponseWriter, response interface{})

ResponseWriterTextHtml function

func ResponseWriterXML

func ResponseWriterXML(writer http.ResponseWriter, response interface{})

ResponseWriterXML function

func SafeAtoi

func SafeAtoi(str string, fallback *int) *int

func Src

func Src(callerDepth int) string

func StringPtr

func StringPtr(str string) *string

func TrimLeftChars

func TrimLeftChars(s string, n int) string

func XmlIt

func XmlIt(a interface{}) string

Types

type GenericResponse

type GenericResponse struct {
	XMLName           *xml.Name `xml:"API3G" json:",omitempty"`
	Result            string    `xml:"Result"`
	ResultExplanation string    `xml:"ResultExplanation"`
}

type HTTPStatusCode

type HTTPStatusCode int

HTTPStatusCode is a type for resolving the returned HTTP Status Code Content

type JsonQuery

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

JsonQuery is an object that enables querying of a Go map with a simple positional query language. All credit goes to https://github.com/jmoiron/jsonq

func NewJsonQuery

func NewJsonQuery(data interface{}) *JsonQuery

NewJsonQuery creates a new JsonQuery obj from an interface{}.

func (*JsonQuery) Array

func (j *JsonQuery) Array(s ...string) ([]interface{}, error)

Array extracts a []interface{} from the JsonQuery

func (*JsonQuery) ArrayOfArrays

func (j *JsonQuery) ArrayOfArrays(s ...string) ([][]interface{}, error)

ArrayOfArrays extracts an array of []interface{} (arrays) from some json

func (*JsonQuery) ArrayOfBools

func (j *JsonQuery) ArrayOfBools(s ...string) ([]bool, error)

ArrayOfBools extracts an array of bools from some json

func (*JsonQuery) ArrayOfFloats

func (j *JsonQuery) ArrayOfFloats(s ...string) ([]float64, error)

ArrayOfFloats extracts an array of float64s from some json

func (*JsonQuery) ArrayOfInts

func (j *JsonQuery) ArrayOfInts(s ...string) ([]int, error)

ArrayOfInts extracts an array of ints from some json

func (*JsonQuery) ArrayOfObjects

func (j *JsonQuery) ArrayOfObjects(s ...string) ([]map[string]interface{}, error)

ArrayOfObjects extracts an array of map[string]interface{} (objects) from some json

func (*JsonQuery) ArrayOfStrings

func (j *JsonQuery) ArrayOfStrings(s ...string) ([]string, error)

ArrayOfStrings extracts an array of strings from some json

func (*JsonQuery) Bool

func (j *JsonQuery) Bool(s ...string) (bool, error)

Bool extracts a bool the JsonQuery

func (*JsonQuery) Float

func (j *JsonQuery) Float(s ...string) (float64, error)

Float extracts a float from the JsonQuery

func (*JsonQuery) Int

func (j *JsonQuery) Int(s ...string) (int, error)

Int extracts an int from the JsonQuery

func (*JsonQuery) Interface

func (j *JsonQuery) Interface(s ...string) (interface{}, error)

Interface extracts an interface{} from the JsonQuery

func (*JsonQuery) Matrix2D

func (j *JsonQuery) Matrix2D(s ...string) ([][]interface{}, error)

Matrix2D is an alias for ArrayOfArrays

func (*JsonQuery) Object

func (j *JsonQuery) Object(s ...string) (map[string]interface{}, error)

Object extracts a json object from the JsonQuery

func (*JsonQuery) String

func (j *JsonQuery) String(s ...string) (string, error)

String extracts a string from the JsonQuery

type MappingBuilder

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

func NewMappingBuilder

func NewMappingBuilder(mappings map[string]string, doc map[string]interface{}) *MappingBuilder

func (*MappingBuilder) BuildBody

func (mb *MappingBuilder) BuildBody() (map[string]interface{}, error)

type MappingStrategy

type MappingStrategy interface {
	// contains filtered or unexported methods
}

type MappingValues

type MappingValues struct {
	MappingValue string
	DataType     string
	IsSortable   bool
}

type SqlQuery

type SqlQuery struct {

	// Filter should be a pointer
	//Filter     *string
	Filter     *strings.Builder
	Parameters map[int]interface{}
	Error      error

	Limit   string
	OrderBy string
	// contains filtered or unexported fields
}

func ParseScimParams

func ParseScimParams(params scim.ListRequestParams, fieldMappings map[filter.AttributePath]MappingValues, orderField string, orderDirection string) (*SqlQuery, error)

func (*SqlQuery) GetParameterList

func (sq *SqlQuery) GetParameterList() []interface{}

Jump to

Keyboard shortcuts

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