Documentation
¶
Overview ¶
Package toolbox - useful set of utilities/abstractions developed as part of datastore connectivity and testing (viant/dsc, viant/dsunit).
Index ¶
- Constants
- Variables
- func AsBoolean(value interface{}) bool
- func AsCompatibleFunctionParameters(function interface{}, parameters []interface{}) ([]interface{}, error)
- func AsFloat(value interface{}) float64
- func AsInt(value interface{}) int
- func AsJSONText(source interface{}) (string, error)
- func AsMap(source interface{}) map[string]interface{}
- func AsSlice(sourceSlice interface{}) []interface{}
- func AsString(input interface{}) string
- func AsTime(value interface{}, dateLayout string) *time.Time
- func AssertKind(input interface{}, kind reflect.Kind, name string)
- func AssertPointerKind(input interface{}, kind reflect.Kind, name string)
- func AssertTypeKind(dataType reflect.Type, kind reflect.Kind, name string)
- func BuildFunctionParameters(function interface{}, parameters []string, ...) ([]interface{}, error)
- func BuildTagMapping(structTemplatePointer interface{}, mappedKeyTag string, ...) map[string](map[string]string)
- func CallFunction(function interface{}, parameters ...interface{}) []interface{}
- func CallerDirectory(callerIndex int) string
- func CallerInfo(callerIndex int) (string, string, int)
- func CanConvertToFloat(value interface{}) bool
- func CanConvertToInt(value interface{}) bool
- func CanConvertToString(input interface{}) bool
- func CopyMapEntries(sourceMap, targetMap interface{})
- func CopySliceElements(sourceSlice, targetSlicePointer interface{})
- func CopyWithBufferPool(source io.Reader, destination io.Writer, pool httputil.BufferPool) (int64, error)
- func CountPointers(value interface{}) int
- func CreateDirIfNotExist(dirs ...string) error
- func DateFormatToLayout(dateFormat string) string
- func DereferenceType(value interface{}) reflect.Type
- func DereferenceValue(value interface{}) interface{}
- func DereferenceValues(source interface{}) interface{}
- func DiscoverCollectionValuesAndKind(values interface{}) ([]interface{}, reflect.Kind)
- func DiscoverComponentType(input interface{}) reflect.Type
- func DiscoverTypeByKind(input interface{}, expected reflect.Kind) reflect.Type
- func DiscoverValueAndKind(input string) (interface{}, reflect.Kind)
- func DiscoverValueByKind(input interface{}, expected reflect.Kind) reflect.Value
- func ExpandFileTemplate(template string) string
- func ExpandParameters(macroEvaluator *MacroEvaluator, parameters map[string]string) error
- func ExpandValue(macroEvaluator *MacroEvaluator, value string) (string, error)
- func ExtractMimeType(file string) string
- func ExtractURIParameters(templateURI, requestURI string) (map[string]string, bool)
- func FileExists(filename string) bool
- func FileFromURL(fileURL string) (string, error)
- func FilterSliceElements(sourceSlice interface{}, predicate interface{}, targetSlicePointer interface{})
- func GetFuncSignature(function interface{}) []reflect.Type
- func GetFunction(owner interface{}, name string) (interface{}, error)
- func GetSliceValue(slice interface{}, index int) interface{}
- func GetTimeLayout(settings map[string]string) string
- func GroupSliceElements(sourceSlice, targetMap, keyFunction interface{})
- func HasSliceAnyElements(sourceSlice interface{}, elements ...interface{}) (result bool)
- func HasTimeLayout(settings map[string]string) bool
- func IndexSlice(slice, resultingMap, keyFunction interface{})
- func InitStruct(source interface{})
- func IsASCIIText(candidate string) bool
- func IsBool(input interface{}) bool
- func IsCompleteJSON(candidate string) bool
- func IsFloat(input interface{}) bool
- func IsFunc(input interface{}) bool
- func IsInt(input interface{}) bool
- func IsMap(input interface{}) bool
- func IsNewLineDelimitedJSON(candidate string) bool
- func IsPointer(input interface{}) bool
- func IsSlice(input interface{}) bool
- func IsString(input interface{}) bool
- func IsStruct(input interface{}) bool
- func IsTime(input interface{}) bool
- func IsValueOfKind(input interface{}, kind reflect.Kind) bool
- func IsZero(input interface{}) bool
- func JSONToInterface(source interface{}) (interface{}, error)
- func JSONToMap(source interface{}) (map[string]interface{}, error)
- func JSONToSlice(source interface{}) ([]interface{}, error)
- func JoinAsString(slice interface{}, separator string) string
- func LoadConfigFromUrl(url string, config interface{}) error
- func MakeReverseStringMap(text string, valueSepartor string, itemSeparator string) map[string]string
- func MakeStringMap(text string, valueSepartor string, itemSeparator string) map[string]string
- func MapKeysToSlice(sourceMap interface{}, targetSlicePointer interface{})
- func MapKeysToStringSlice(sourceMap interface{}) []string
- func NewBytes(input []byte) []byte
- func NewBytesBufferPool(poolSize, bufferSize int) httputil.BufferPool
- func NewFieldSettingByKey(aStruct interface{}, key string) map[string](map[string]string)
- func NewHttpClient(options ...*HttpOptions) (*http.Client, error)
- func NewLineDelimitedJSON(candidate string) ([]interface{}, error)
- func OpenFile(filename string) (*os.File, error)
- func OpenReaderFromURL(rawURL string) (io.ReadCloser, string, error)
- func OpenURL(fileURL string, flag int, permissions os.FileMode) (*os.File, error)
- func ParseTime(input, layout string) (time.Time, error)
- func Process2DSliceInBatches(slice [][]interface{}, size int, handler func(batchedSlice [][]interface{}))
- func ProcessMap(sourceMap interface{}, handler func(key, value interface{}) bool)
- func ProcessSlice(slice interface{}, handler func(item interface{}) bool)
- func ProcessSliceWithIndex(slice interface{}, handler func(index int, item interface{}) bool)
- func ProcessStruct(aStruct interface{}, ...) error
- func QueryBoolValue(u *url.URL, name string, defaultValue bool) bool
- func QueryIntValue(u *url.URL, name string, defaultValue int) int
- func QueryValue(u *url.URL, name, defaultValue string) string
- func RemoveFileIfExist(filenames ...string) error
- func ReverseSlice(source interface{})
- func RouteToService(method, url string, request, response interface{}) (err error)
- func SetSliceValue(slice interface{}, index int, value interface{})
- func SliceToMap(sourceSlice, targetMap, keyFunction, valueFunction interface{})
- func SliceToMultimap(sourceSlice, targetMap, keyFunction, valueFunction interface{})
- func SortStrings(source []string) []string
- func TimestampToString(dateFormat string, unixTimestamp, unixNanoTimestamp int64) string
- func ToFloat(value interface{}) (float64, error)
- func ToInt(value interface{}) (int, error)
- func ToTime(value interface{}, dateLayout string) (*time.Time, error)
- func TransformSlice(sourceSlice, targetSlicePointer, transformer interface{})
- func URLBase(URL string) string
- func URLPathJoin(baseURL, path string) string
- func URLSplit(URL string) (string, string)
- func UnwrapValue(value *reflect.Value) interface{}
- func WriteServiceRoutingResponse(response http.ResponseWriter, request *http.Request, ...) error
- type BatchLimiter
- type BodyMatcher
- type ByteWriterAt
- type CharactersMatcher
- type Context
- type Converter
- type Decoder
- type DecoderFactory
- type DelimitedRecord
- type Dictionary
- type EOFMatcher
- type Encoder
- type EncoderFactory
- type FieldInfo
- type FileInfo
- type FileLogger
- type FileLoggerConfig
- type FileSetInfo
- type FunctionInfo
- type HandlerInvoker
- type HttpOptions
- type IdMatcher
- type IntMatcher
- type Iterator
- type KeywordMatcher
- type KeywordsMatcher
- type LiteralMatcher
- type LogMessage
- type LogMessages
- type LogStream
- type MacroEvaluator
- type MapDictionary
- type Marshaler
- type Matcher
- type Predicate
- func NewBetweenPredicate(from, to interface{}) Predicate
- func NewComparablePredicate(operator string, leftOperand interface{}) Predicate
- func NewInPredicate(values ...interface{}) Predicate
- func NewLikePredicate(matching string) Predicate
- func NewNilPredicate() Predicate
- func NewWithinPredicate(baseTime time.Time, deltaInSeconds int, dateLayout string) Predicate
- type ServiceRouter
- type ServiceRouting
- type StatusCodeSettable
- type StructFieldMeta
- type StructInfo
- func (s *StructInfo) AddFields(fields ...*FieldInfo)
- func (s *StructInfo) AddReceivers(receivers ...*FunctionInfo)
- func (s *StructInfo) Field(name string) *FieldInfo
- func (s *StructInfo) Fields() []*FieldInfo
- func (s *StructInfo) HasField(name string) bool
- func (s *StructInfo) HasReceiver(name string) bool
- func (s *StructInfo) Receiver(name string) *FunctionInfo
- func (s *StructInfo) Receivers() []*FunctionInfo
- type StructMeta
- type Token
- type Tokenizer
- type ToolboxHTTPClient
- type UnMarshaler
- type ValueProvider
- func NewBetweenPredicateValueProvider() ValueProvider
- func NewCastedValueProvider() ValueProvider
- func NewCurrentDateProvider() ValueProvider
- func NewCurrentTimeProvider() ValueProvider
- func NewDateOfBirthrovider() ValueProvider
- func NewDictionaryProvider(contextKey interface{}) ValueProvider
- func NewEnvValueProvider() ValueProvider
- func NewFileValueProvider(trim bool) ValueProvider
- func NewNilValueProvider() ValueProvider
- func NewTimeDiffProvider() ValueProvider
- func NewWeekdayProvider() ValueProvider
- func NewWithinSecPredicateValueProvider() ValueProvider
- type ValueProviderRegistry
- type Zeroable
Constants ¶
const ( //JSONMimeType JSON mime type constant JSONMimeType = "text/json" //CSVMimeType csv mime type constant CSVMimeType = "text/csv" //TSVMimeType tab separated mime type constant TSVMimeType = "text/tsv" //TextMimeType mime type constant TextMimeType = "text/sql" )
const ( MethodGet = "GET" MethodHead = "HEAD" MethodPost = "POST" MethodPut = "PUT" MethodPatch = "PATCH" // RFC 5789 MethodDelete = "DELETE" MethodOptions = "OPTIONS" MethodTrace = "TRACE" )
Variables ¶
var CopyStringValueProvider = func(source string) string {
return source
}
CopyStringValueProvider is a function that returns passed in string This provider can be used to make map from slice like map[string]some type
var DateFormatKeyword = "dateFormat"
DateFormatKeyword constant 'dateFormat' key
var DateLayoutKeyword = "dateLayout"
DateLayoutKeyword constant 'dateLayout' key
var DefaultDateLayout = "2006-01-02 15:04:05.000"
DefaultDateLayout is set to 2006-01-02 15:04:05.000
var DefaultDecoderFactory = NewJSONDecoderFactory()
DefaultDecoderFactory - NewJSONDecoderFactory
var DefaultEncoderFactory = NewJSONEncoderFactory()
DefaultEncoderFactory - NewJSONEncoderFactory
var FileExtensionMimeType = map[string]string{ "json": JSONMimeType, "csv": CSVMimeType, "tsv": TSVMimeType, "sql": TextMimeType, "html": "text/html", "js": "text/javascript", "jpg": "image/jpeg", "png": "image/png", }
FileExtensionMimeType json, csv, tsc, sql mime types.
var FileSchema = "file://"
FileSchema file://
var TrueProvider = func(input interface{}) bool { return true }
var TrueValueProvider = func(ignore interface{}) bool { return true }
TrueValueProvider is a function that returns true, it takes one parameters which ignores, This provider can be used to make map from slice like map[some type]bool
Functions ¶
func AsCompatibleFunctionParameters ¶
func AsCompatibleFunctionParameters(function interface{}, parameters []interface{}) ([]interface{}, error)
AsCompatibleFunctionParameters takes incompatible function parameters and converts then into provided function signature compatible
func AsJSONText ¶
AsJSONText converts data structure int text JSON
func AsMap ¶
func AsMap(source interface{}) map[string]interface{}
AsMap converts underlying map as map[string]interface{}
func AsSlice ¶
func AsSlice(sourceSlice interface{}) []interface{}
AsSlice converts underlying slice as []interface{}
func AssertKind ¶
AssertKind checks if input is of the passed in kind, if not it panic with message including name
func AssertPointerKind ¶
AssertPointerKind checks if input is a pointer of the passed in kind, if not it panic with message including name
func AssertTypeKind ¶
AssertTypeKind checks if dataType is of the passed in kind, if not it panic with message including name
func BuildFunctionParameters ¶
func BuildFunctionParameters(function interface{}, parameters []string, parameterValues map[string]interface{}) ([]interface{}, error)
BuildFunctionParameters builds function parameters provided in the parameterValues. Parameters value will be converted if needed to expected by the function signature type. It returns function parameters , or error
func BuildTagMapping ¶
func BuildTagMapping(structTemplatePointer interface{}, mappedKeyTag string, resultExclusionTag string, inheritKeyFromField bool, convertKeyToLowerCase bool, tags []string) map[string](map[string]string)
BuildTagMapping builds map keyed by mappedKeyTag tag value, and value is another map of keys where tag name is presents in the tags parameter.
func CallFunction ¶
func CallFunction(function interface{}, parameters ...interface{}) []interface{}
CallFunction calls passed in function with provided parameters,it returns a function result.
func CallerDirectory ¶
CallerDirectory returns directory of caller source code directory
func CallerInfo ¶
CallerInfo return filename, function or file line from the stack
func CanConvertToFloat ¶
func CanConvertToFloat(value interface{}) bool
CanConvertToFloat checkis if float conversion is possible.
func CanConvertToInt ¶
func CanConvertToInt(value interface{}) bool
CanConvertToInt returns true if an input can be converted to int value.
func CanConvertToString ¶
func CanConvertToString(input interface{}) bool
CanConvertToString checks if input can be converted to string
func CopyMapEntries ¶
func CopyMapEntries(sourceMap, targetMap interface{})
CopyMapEntries appends map entry from source map to target map
func CopySliceElements ¶
func CopySliceElements(sourceSlice, targetSlicePointer interface{})
CopySliceElements appends elements from source slice into target This function comes handy if you want to copy from generic []interface{} slice to more specific slice like []string, if source slice element are of the same time
func CopyWithBufferPool ¶
func CopyWithBufferPool(source io.Reader, destination io.Writer, pool httputil.BufferPool) (int64, error)
CopyBuffer copies bytes from passed in source to destination with provided pool
func CountPointers ¶
func CountPointers(value interface{}) int
CountPointers count pointers to undelying non pointer type
func CreateDirIfNotExist ¶
CreateDirIfNotExist creates directory if they do not exist
func DateFormatToLayout ¶
DateFormatToLayout converts java date format https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html#rfc822timezone into go date layout
func DereferenceType ¶
DereferenceType dereference passed in value
func DereferenceValue ¶
func DereferenceValue(value interface{}) interface{}
DereferenceValue dereference passed in value
func DereferenceValues ¶
func DereferenceValues(source interface{}) interface{}
DereferenceValues replaces pointer to its value within a generic map or slice
func DiscoverCollectionValuesAndKind ¶
DiscoverCollectionValuesAndKind discovers passed in slice item kind, and returns slice of values converted to discovered type. It tries the following kind int, float, bool, string
func DiscoverComponentType ¶
DiscoverComponentType returns type unwrapped from pointer, slice or map
func DiscoverTypeByKind ¶
DiscoverTypeByKind returns unwrapped input type that matches expected kind, or panic if this is not possible
func DiscoverValueAndKind ¶
DiscoverValueAndKind discovers input kind, it applies checks of the following types: int, float, bool, string
func DiscoverValueByKind ¶
DiscoverValueByKind returns unwrapped input that matches expected kind, or panic if this is not possible
func ExpandFileTemplate ¶
ExpandFileTemplate expands
func ExpandParameters ¶
func ExpandParameters(macroEvaluator *MacroEvaluator, parameters map[string]string) error
ExpandParameters expands passed in parameters as strings
func ExpandValue ¶
func ExpandValue(macroEvaluator *MacroEvaluator, value string) (string, error)
ExpandValue expands passed in value, it returns expanded string value or error
func ExtractMimeType ¶
ExtractMimeType extracts mime type by extension
func ExtractURIParameters ¶
ExtractURIParameters parses URIs to extract {<param>} defined in templateURI from requestURI, it returns extracted parameters and flag if requestURI matched templateURI
func FileFromURL ¶
FileFromURL returns file path from passed in URL.
func FilterSliceElements ¶
func FilterSliceElements(sourceSlice interface{}, predicate interface{}, targetSlicePointer interface{})
FilterSliceElements copies elements from sourceSlice to targetSlice if predicate function returns true. Predicate function needs to accept source slice element type and return true.
func GetFuncSignature ¶
GetFuncSignature returns a function signature
func GetFunction ¶
GetFunction returns function for provided owner and name, or error
func GetSliceValue ¶
func GetSliceValue(slice interface{}, index int) interface{}
GetSliceValue gets value from passed in index
func GetTimeLayout ¶
GetTimeLayout returns time laout from passed in map, first it check if DateLayoutKeyword is defined is so it returns it, otherwise it check DateFormatKeyword and if exists converts it to dateLayout If neithers keys exists it panics, please use HasTimeLayout to avoid panic
func GroupSliceElements ¶
func GroupSliceElements(sourceSlice, targetMap, keyFunction interface{})
GroupSliceElements reads source slice and transfer all values returned by keyFunction to a slice in target map.
func HasSliceAnyElements ¶
func HasSliceAnyElements(sourceSlice interface{}, elements ...interface{}) (result bool)
HasSliceAnyElements checks if sourceSlice has any of passed in elements. This method iterates through elements till if finds the first match.
func HasTimeLayout ¶
HasTimeLayout checks if dateLayout can be taken from the passed in setting map
func IndexSlice ¶
func IndexSlice(slice, resultingMap, keyFunction interface{})
IndexSlice reads passed in slice and applies function that takes a slice item as argument to return a key value. passed in resulting map needs to match key type return by a key function, and accept slice item type as argument.
func InitStruct ¶
func InitStruct(source interface{})
InitStruct initialise any struct pointer to empty struct
func IsASCIIText ¶
IsASCIIText return true if supplied string does not have binary data
func IsCompleteJSON ¶
IsCompleteJSON returns true if supplied represent complete JSON
func IsNewLineDelimitedJSON ¶
IsNewLineDelimitedJSON returns true if supplied content is multi line delimited JSON
func IsPointer ¶
func IsPointer(input interface{}) bool
IsPointer returns true if input is a pointer
func IsValueOfKind ¶
IsValueOfKind returns true if passed in input is of supplied kind.
func JSONToInterface ¶
func JSONToInterface(source interface{}) (interface{}, error)
JSONToInterface converts JSON source to an interface (either map or slice)
func JSONToSlice ¶
func JSONToSlice(source interface{}) ([]interface{}, error)
JSONToSlice converts JSON source into slice
func JoinAsString ¶
JoinAsString joins all items of a slice, with separator, it takes any slice as argument,
func LoadConfigFromUrl ¶
LoadConfigFromUrl loads json configuration from url to passed in config pointer.
func MakeReverseStringMap ¶
func MakeReverseStringMap(text string, valueSepartor string, itemSeparator string) map[string]string
MakeReverseStringMap creates a mapstring]string from string, the values become key, and key values
func MakeStringMap ¶
MakeStringMap creates a mapstring]string from string,
func MapKeysToSlice ¶
func MapKeysToSlice(sourceMap interface{}, targetSlicePointer interface{})
MapKeysToSlice appends all map keys to targetSlice
func MapKeysToStringSlice ¶
func MapKeysToStringSlice(sourceMap interface{}) []string
MapKeysToStringSlice creates a string slice from sourceMap keys, keys do not need to be of a string type.
func NewBytesBufferPool ¶
func NewBytesBufferPool(poolSize, bufferSize int) httputil.BufferPool
NewBytesBufferPool returns new httputil.BufferPool pool.
func NewFieldSettingByKey ¶
NewFieldSettingByKey reads field's tags and returns them indexed by passed in key, fieldName is always part of the resulting map unless filed has "transient" tag.
func NewHttpClient ¶
func NewHttpClient(options ...*HttpOptions) (*http.Client, error)
func NewLineDelimitedJSON ¶
NewLineDelimitedJSON returns JSON for supplied multi line JSON
func OpenFile ¶
OpenFile open file converting path to elements and rebuling path safety with path.Join
func OpenReaderFromURL ¶
func OpenReaderFromURL(rawURL string) (io.ReadCloser, string, error)
OpenReaderFromURL opens a reader from URL to indicate a relative path from the working directory the schema must start with "file://.../". "..." will be replaced by the working directory. Note that you can not have a relative path in the middle of the uri. for instance, "file:///local/../path is not valid
func Process2DSliceInBatches ¶
func Process2DSliceInBatches(slice [][]interface{}, size int, handler func(batchedSlice [][]interface{}))
Process2DSliceInBatches iterates over any 2 dimensional slice, it calls handler with batch.
func ProcessMap ¶
func ProcessMap(sourceMap interface{}, handler func(key, value interface{}) bool)
ProcessMap iterates over any map, it calls handler with every key, value pair unless handler returns false.
func ProcessSlice ¶
func ProcessSlice(slice interface{}, handler func(item interface{}) bool)
ProcessSlice iterates over any slice, it calls handler with each element unless handler returns false,
func ProcessSliceWithIndex ¶
ProcessSliceWithIndex iterates over any slice, it calls handler with every index and item unless handler returns false
func ProcessStruct ¶
func ProcessStruct(aStruct interface{}, handler func(fieldType reflect.StructField, field reflect.Value) error) error
ProcessStruct reads passed in struct fields and values to pass it to provided handler
func QueryBoolValue ¶
QueryBoolValue returns query value for passed in url's name or default value
func QueryIntValue ¶
QueryIntValue returns query value for passed in url's name or default value
func QueryValue ¶
QueryValue returns query value for passed in url's name or default value
func RemoveFileIfExist ¶
RemoveFileIfExist remove file if exists
func ReverseSlice ¶
func ReverseSlice(source interface{})
ProcessSlice iterates over any slice, it calls handler with each element unless handler returns false,
func RouteToService ¶
RouteToService calls web service url, with passed in json request, and encodes http json response into passed response
func SetSliceValue ¶
func SetSliceValue(slice interface{}, index int, value interface{})
SetSliceValue sets value at slice index
func SliceToMap ¶
func SliceToMap(sourceSlice, targetMap, keyFunction, valueFunction interface{})
SliceToMap reads passed in slice to to apply the key and value function for each item. Result of these calls is placed in the resulting map.
func SliceToMultimap ¶
func SliceToMultimap(sourceSlice, targetMap, keyFunction, valueFunction interface{})
SliceToMultimap reads source slice and transfer all values by valueFunction and returned by keyFunction to a slice in target map. Key and value function result type need to agree with target map type.
func SortStrings ¶
SortStrings creates a new copy of passed in slice and sorts it.
func TimestampToString ¶
TimestampToString formats timestamp to passed in java style date format
func TransformSlice ¶
func TransformSlice(sourceSlice, targetSlicePointer, transformer interface{})
TransformSlice appends transformed elements from source slice into target, transformer take as argument item of source slice and return value of target slice.
func URLPathJoin ¶
func WriteServiceRoutingResponse ¶
func WriteServiceRoutingResponse(response http.ResponseWriter, request *http.Request, serviceRouting *ServiceRouting, result interface{}) error
WriteServiceRoutingResponse writes service router response
Types ¶
type BatchLimiter ¶
func NewBatchLimiter ¶
func NewBatchLimiter(batchSize, total int) *BatchLimiter
func (*BatchLimiter) Acquire ¶
func (r *BatchLimiter) Acquire()
func (*BatchLimiter) Done ¶
func (r *BatchLimiter) Done()
func (*BatchLimiter) Wait ¶
func (r *BatchLimiter) Wait()
type BodyMatcher ¶
LiteralMatcher represents a matcher that finds any literals in the input
type ByteWriterAt ¶
type ByteWriterAt struct { Buffer []byte // contains filtered or unexported fields }
ByteWriterAt represents a bytes writer at
func NewByteWriterAt ¶
func NewByteWriterAt() *ByteWriterAt
NewWriterAt returns a new instance of byte writer at
type CharactersMatcher ¶
type CharactersMatcher struct {
Chars string //characters to be matched
}
CharactersMatcher represents a matcher, that matches any of Chars.
type Context ¶
type Context interface { //GetRequired returns a value for a target type of error if it does not exist GetRequired(targetType interface{}) (interface{}, error) //GetOptional returns a value for a target type GetOptional(targetType interface{}) interface{} //GetOptional into sets requested context value into target, returns true if value was found GetInto(targetType interface{}, target interface{}) bool //Put puts target type value to the context, or error if value exists, is nil or incompatible with target type Put(targetType interface{}, value interface{}) error //Replace repaces value in the context Replace(targetType interface{}, value interface{}) error //Remove removes value from the context Remove(targetType interface{}) interface{} //Contains chekcs if a value of a terget type is in contet Contains(targetType interface{}) bool //Clone create a shallow copy of a context Clone() Context }
Context represents type safe map.
type Converter ¶
Converter represets data converter, it converts incompatibe data structure, like map and struct, string and time, *string to string, etc.
func NewColumnConverter ¶
NewColumnConverter create a new converter, that has ability to convert map to struct using column mapping
func (*Converter) AssignConverted ¶
AssignConverted assign to the target source, target needs to be pointer, input has to be convertible or compatible type
type Decoder ¶
type Decoder interface { //Decode reads and decodes objects from an input stream. Decode(v interface{}) error }
Decoder represents a decoder.
type DecoderFactory ¶
type DecoderFactory interface { //Create a decoder for passed in io reader Create(reader io.Reader) Decoder }
DecoderFactory create an decoder for passed in input stream
func NewDelimiterDecoderFactory ¶
func NewDelimiterDecoderFactory() DecoderFactory
NewDelimiterDecoderFactory returns a new delimitered decoder factory.
func NewJSONDecoderFactory ¶
func NewJSONDecoderFactory() DecoderFactory
NewJSONDecoderFactory create a new JSONDecoderFactory
func NewJSONDecoderFactoryWithOption ¶
func NewJSONDecoderFactoryWithOption(useNumber bool) DecoderFactory
NewJSONDecoderFactoryWithOption create a new JSONDecoderFactory, it takes useNumber decoder parameter
func NewUnMarshalerDecoderFactory ¶
func NewUnMarshalerDecoderFactory() DecoderFactory
NewUnMarshalerDecoderFactory returns a decoder factory
func NewYamlDecoderFactory ¶
func NewYamlDecoderFactory() DecoderFactory
NewYamlDecoderFactory create a new yaml decoder factory
type DelimitedRecord ¶
DelimitedRecord represents a delimited record
func (*DelimitedRecord) IsEmpty ¶
func (r *DelimitedRecord) IsEmpty() bool
IsEmpty returns true if all values are empty or null
type Dictionary ¶
type Dictionary interface { //Get returns value for passed in key or error Get(key string) (interface{}, error) //Exists checks if key exists Exists(key string) bool }
Dictionary represents simply lookup interface
type Encoder ¶
type Encoder interface { //Encode encodes an instance to output stream Encode(object interface{}) error }
Encoder writes an instance to output stream
type EncoderFactory ¶
type EncoderFactory interface { //Create creates an encoder for an output stream Create(writer io.Writer) Encoder }
EncoderFactory create an encoder for an output stream
func NewJSONEncoderFactory ¶
func NewJSONEncoderFactory() EncoderFactory
NewJSONEncoderFactory creates new NewJSONEncoderFactory
func NewMarshalerEncoderFactory ¶
func NewMarshalerEncoderFactory() EncoderFactory
NewMarshalerEncoderFactory create a new encoder factory for marsheler struct
func NewYamlEncoderFactory ¶
func NewYamlEncoderFactory() EncoderFactory
NewYamlEncoderFactory create a new yaml encoder factory
type FieldInfo ¶
type FieldInfo struct { Name string TypeName string KeyTypeName string ValueTypeName string TypePackage string IsMap bool IsChannel bool IsSlice bool IsStruct bool IsPointer bool Tag string Comment string }
FieldInfo represents a filed info
func NewFieldInfo ¶
NewFieldInfo creates a new field info.
type FileInfo ¶
type FileInfo struct {
// contains filtered or unexported fields
}
FileInfo represent hold definition about all defined structs and its receivers in a file
func NewFileInfo ¶
Visit creates a new file info.
func (*FileInfo) HasStructInfo ¶
HasStructInfo returns truc if struct info is defined in a file
func (*FileInfo) Struct ¶
func (f *FileInfo) Struct(name string) *StructInfo
Struct returns a struct info for passed in name
func (*FileInfo) Structs ¶
func (f *FileInfo) Structs() []*StructInfo
Struct returns all struct info
type FileLogger ¶
type FileLogger struct {
// contains filtered or unexported fields
}
FileLogger represents a file logger
func NewFileLogger ¶
func NewFileLogger(configs ...FileLoggerConfig) (*FileLogger, error)
NewFileLogger create new file logger
func (*FileLogger) Log ¶
func (l *FileLogger) Log(message *LogMessage) error
Log logs message into stream
func (*FileLogger) NewLogStream ¶
func (l *FileLogger) NewLogStream(path string, config *FileLoggerConfig) (*LogStream, error)
NewLogStream creat a new LogStream for passed om path and file config
func (*FileLogger) Notify ¶
func (l *FileLogger) Notify(siginal os.Signal)
type FileLoggerConfig ¶
type FileLoggerConfig struct { LogType string FileTemplate string QueueFlashCount int MaxQueueSize int FlushRequencyInMs int //type backward-forward compatibility FlushFrequencyInMs int MaxIddleTimeInSec int }
FileLoggerConfig represents FileLogger
func (*FileLoggerConfig) Validate ¶
func (c *FileLoggerConfig) Validate() error
Validate valides configuration sttings
type FileSetInfo ¶
type FileSetInfo struct {
// contains filtered or unexported fields
}
FileSetInfo represents a fileset info storing information about go file with their struct definition
func NewFileSetInfo ¶
func NewFileSetInfo(baseDir string) (*FileSetInfo, error)
NewFileSetInfo creates a new fileset info
func (*FileSetInfo) FileInfo ¶
func (f *FileSetInfo) FileInfo(name string) *FileInfo
FileInfo returns fileinfo for supplied file name
func (*FileSetInfo) FilesInfo ¶
func (f *FileSetInfo) FilesInfo() map[string]*FileInfo
FilesInfo returns all files info.
func (*FileSetInfo) Struct ¶
func (f *FileSetInfo) Struct(name string) *StructInfo
StructInfo returns struct info for passed in struct name.
type FunctionInfo ¶
type FunctionInfo struct { Name string ReceiverTypeName string ParameterFields []*FieldInfo ResultsFields []*FieldInfo }
FunctionInfo represents a function info
func NewFunctionInfo ¶
func NewFunctionInfo(funcDeclaration *ast.FuncDecl) *FunctionInfo
NewFunctionInfo create a new function
type HandlerInvoker ¶
type HandlerInvoker func(serviceRouting *ServiceRouting, request *http.Request, response http.ResponseWriter, parameters map[string]interface{}) error
HandlerInvoker method is responsible of passing required parameters to router handler.
type HttpOptions ¶
type HttpOptions struct { Key string Value interface{} }
type IdMatcher ¶
type IdMatcher struct{}
LiteralMatcher represents a matcher that finds any literals in the input
type IntMatcher ¶
type IntMatcher struct{}
IntMatcher represents a matcher that finds any int in the input
type Iterator ¶
type Iterator interface { //HasNext returns true if iterator has next element. HasNext() bool //Next sets item pointer with next element. Next(itemPointer interface{}) error }
Iterator represents generic iterator.
func NewSliceIterator ¶
func NewSliceIterator(slice interface{}) Iterator
NewSliceIterator creates a new slice iterator.
type KeywordMatcher ¶
KeywordMatcher represents a keyword matcher
type KeywordsMatcher ¶
KeywordsMatcher represents a matcher that finds any of specified keywords in the input
type LiteralMatcher ¶
type LiteralMatcher struct{}
LiteralMatcher represents a matcher that finds any literals in the input
type LogMessage ¶
type LogMessage struct { MessageType string Message interface{} }
LogMessage represent log message
type LogMessages ¶
type LogMessages struct {
Messages []LogMessage
}
LogMessages represents log messages
type LogStream ¶
type LogStream struct { Name string Logger *FileLogger Config *FileLoggerConfig RecordCount int File *os.File LastAddQueueTime time.Time LastWriteTime uint64 Messages chan string Complete chan bool }
LogStream represents individual log stream
func (*LogStream) Log ¶
func (s *LogStream) Log(message *LogMessage) error
Log logs message into stream
type MacroEvaluator ¶
type MacroEvaluator struct {
Prefix, Postfix string
ValueProviderRegistry ValueProviderRegistry
}
MacroEvaluator represents a macro expression evaluator, macros has the following format macro prefix [macro parameter] macro postfix
func NewMacroEvaluator ¶
func NewMacroEvaluator(prefix, postfix string, registry ValueProviderRegistry) *MacroEvaluator
NewMacroEvaluator returns a new macro evaluator
func (*MacroEvaluator) Expand ¶
func (e *MacroEvaluator) Expand(context Context, input string) (interface{}, error)
Expand expands passed in input, it returns expanded value of any type or error
func (*MacroEvaluator) HasMacro ¶
func (e *MacroEvaluator) HasMacro(candidate string) bool
HasMacro checks if candidate has a macro fragment
type MapDictionary ¶
type MapDictionary map[string]interface{}
MapDictionary alias to map of string and interface{}
func (*MapDictionary) Exists ¶
func (d *MapDictionary) Exists(name string) bool
func (*MapDictionary) Get ¶
func (d *MapDictionary) Get(name string) (interface{}, error)
type Marshaler ¶
type Marshaler interface { //Marshal converts bytes to attributes of owner struct Marshal() (data []byte, err error) }
Marshaler represents byte to object converter
type Matcher ¶
type Matcher interface { //Match matches input starting from offset, it return number of characters matched Match(input string, offset int) (matched int) }
Matcher represents a matcher, that matches input from offset position, it returns number of characters matched.
type Predicate ¶
type Predicate interface {
Apply(value interface{}) bool
}
Predicate represents a generic predicate
func NewBetweenPredicate ¶
func NewBetweenPredicate(from, to interface{}) Predicate
NewBetweenPredicate creates a new BETWEEN predicate, it takes from, and to.
func NewComparablePredicate ¶
NewComparablePredicate create a new comparable predicate for =, !=, >=, <=
func NewInPredicate ¶
func NewInPredicate(values ...interface{}) Predicate
NewInPredicate creates a new IN predicate
func NewLikePredicate ¶
NewLikePredicate create a new like predicate
type ServiceRouter ¶
type ServiceRouter struct {
// contains filtered or unexported fields
}
ServiceRouter represents routing rule
func NewServiceRouter ¶
func NewServiceRouter(serviceRouting ...ServiceRouting) *ServiceRouter
NewServiceRouter creates a new service router, is takes list of service routing as arguments
func (*ServiceRouter) Route ¶
func (r *ServiceRouter) Route(response http.ResponseWriter, request *http.Request) error
Route matches service routing by http method , and number of parameters, then it call routing method, and sent back its response.
func (*ServiceRouter) WriteResponse ¶
func (r *ServiceRouter) WriteResponse(encoderFactory EncoderFactory, response interface{}, request *http.Request, responseWriter http.ResponseWriter) error
WriteResponse writes response to response writer, it used encoder factory to encode passed in response to the writer, it sets back request contenttype to response.
type ServiceRouting ¶
type ServiceRouting struct { URI string //matching uri Handler interface{} //has to be func HTTPMethod string Parameters []string ContentTypeEncoders map[string]EncoderFactory //content type encoder factory ContentTypeDecoders map[string]DecoderFactory //content type decoder factory HandlerInvoker HandlerInvoker //optional function that will be used instead of reflection to invoke a handler. }
ServiceRouting represents a simple web services routing rule, which is matched with http request
type StatusCodeSettable ¶
type StatusCodeSettable interface {
SetStatusCode(code int)
}
type StructFieldMeta ¶
type StructFieldMeta struct { Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` Required bool `json:"required,"` Description string `json:"description,omitempty"` }
StructFieldMeta represents struct field meta
type StructInfo ¶
type StructInfo struct { Name string Package string FileName string Comment string Settings map[string]string // contains filtered or unexported fields }
StructInfo represents a struct info
func NewStructInfo ¶
func NewStructInfo(name string) *StructInfo
NewStructInfo creates a new struct info
func (*StructInfo) AddFields ¶
func (s *StructInfo) AddFields(fields ...*FieldInfo)
AddFields appends fileds to structinfo
func (*StructInfo) AddReceivers ¶
func (s *StructInfo) AddReceivers(receivers ...*FunctionInfo)
AddReceivers adds receiver for the struct
func (*StructInfo) Field ¶
func (s *StructInfo) Field(name string) *FieldInfo
Field returns filedinfo for supplied file name
func (*StructInfo) HasField ¶
func (s *StructInfo) HasField(name string) bool
HasField returns true if struct has passed in field.
func (*StructInfo) HasReceiver ¶
func (s *StructInfo) HasReceiver(name string) bool
HasReceiver returns true if receiver is defined for struct
func (*StructInfo) Receiver ¶
func (s *StructInfo) Receiver(name string) *FunctionInfo
Receiver returns receiver for passed in name
func (*StructInfo) Receivers ¶
func (s *StructInfo) Receivers() []*FunctionInfo
Receivers returns struct functions
type StructMeta ¶
type StructMeta struct { Type string Fields []*StructFieldMeta `json:"fields,omitempty"` Dependencies []*StructMeta `json:"dependencies,omitempty"` }
StructMeta represents struct meta details
func GetStructMeta ¶
func GetStructMeta(source interface{}) *StructMeta
type Tokenizer ¶
type Tokenizer struct { Input string Index int InvalidToken int EndOfFileToken int // contains filtered or unexported fields }
Tokenizer represents a token scanner.
func NewTokenizer ¶
func NewTokenizer(input string, invalidToken int, endOfFileToken int, matcher map[int]Matcher) *Tokenizer
NewTokenizer creates a new NewTokenizer, it takes input, invalidToken, endOfFileToeken, and matchers.
type ToolboxHTTPClient ¶
type ToolboxHTTPClient struct {
// contains filtered or unexported fields
}
ToolboxHTTPClient contains preconfigured http client
func NewToolboxHTTPClient ¶
func NewToolboxHTTPClient(options ...*HttpOptions) (*ToolboxHTTPClient, error)
NewToolboxHTTPClient instantiate new client with provided options
func (*ToolboxHTTPClient) Request ¶
func (c *ToolboxHTTPClient) Request(method, url string, request, response interface{}, encoderFactory EncoderFactory, decoderFactory DecoderFactory) (err error)
Request sends http request using the existing client
type UnMarshaler ¶
UnMarshaler represent an struct that can be converted to bytes
type ValueProvider ¶
type ValueProvider interface { //Get returns a value for passed in context and arguments. Context can be used to manage state. Get(context Context, arguments ...interface{}) (interface{}, error) }
ValueProvider represents a value provider
func NewBetweenPredicateValueProvider ¶
func NewBetweenPredicateValueProvider() ValueProvider
NewBetweenPredicateValueProvider returns a new between value provider
func NewCastedValueProvider ¶
func NewCastedValueProvider() ValueProvider
NewCastedValueProvider return a provider that return casted value type
func NewCurrentDateProvider ¶
func NewCurrentDateProvider() ValueProvider
NewCurrentDateProvider returns a provider that returns current date in the format yyyymmdd, i.e. 20170205
func NewCurrentTimeProvider ¶
func NewCurrentTimeProvider() ValueProvider
NewCurrentTimeProvider returns a provder that returns time.Now()
func NewDateOfBirthrovider ¶
func NewDateOfBirthrovider() ValueProvider
NewDateOfBirthValueProvider provider for computing date for supplied expected age, month and day
func NewDictionaryProvider ¶
func NewDictionaryProvider(contextKey interface{}) ValueProvider
NewDictionaryProvider creates a new Dictionary provider, it takes a key context that is a MapDictionary pointer
func NewEnvValueProvider ¶
func NewEnvValueProvider() ValueProvider
NewEnvValueProvider returns a provider that returns a value of env variables.
func NewFileValueProvider ¶
func NewFileValueProvider(trim bool) ValueProvider
NewFileValueProvider create new file value provider
func NewNilValueProvider ¶
func NewNilValueProvider() ValueProvider
NewNilValueProvider returns a provider that returns a nil
func NewTimeDiffProvider ¶
func NewTimeDiffProvider() ValueProvider
NewTimeDiffProvider returns a provider that delta, time unit and optionally format format as java date format or unix or timestamp
func NewWeekdayProvider ¶
func NewWeekdayProvider() ValueProvider
func NewWithinSecPredicateValueProvider ¶
func NewWithinSecPredicateValueProvider() ValueProvider
NewWithinSecPredicateValueProvider returns a new within second value provider
type ValueProviderRegistry ¶
type ValueProviderRegistry interface { Register(name string, valueProvider ValueProvider) Contains(name string) bool Names() []string Get(name string) ValueProvider }
ValueProviderRegistry registry of value providers
func NewValueProviderRegistry ¶
func NewValueProviderRegistry() ValueProviderRegistry
NewValueProviderRegistry create new NewValueProviderRegistry
Source Files
¶
- batch_limiter.go
- byte_buffer_pool.go
- collections.go
- config_helper.go
- context.go
- converter.go
- decoder.go
- doc.go
- encoder.go
- file_logger.go
- fileset_info.go
- function_util.go
- iterator.go
- json.go
- log_message.go
- macro.go
- mime_type.go
- os_helper.go
- predicate.go
- predicates.go
- service_router.go
- stack_helper.go
- struct_helper.go
- text.go
- time_format.go
- tokenizer.go
- types.go
- uri.go
- uri_helper.go
- value_provider.go
- writer_at.go