toolbox

package module
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2019 License: Apache-2.0 Imports: 32 Imported by: 0

README

Toolbox - go utility library

GoReportCard GoDoc

This library is compatible with Go 1.8+

Please refer to CHANGELOG.md if you encounter breaking changes.

Motivation

This library was developed as part of Datastore Connectivity and Testibility libraries: (Assertly, Datastore testing, End to end testing) as a way to share utilities, and other abstractions that may be useful in other projects.

Collection Utilities
Iterator

Example

	slice := []string{"a", "z", "c"}
	iterator := toolbox.NewSliceIterator(slice)
    value := ""
    for iterator.HasNext() {
        iterator.Next(&value)
        ...
    }
Slice utilities

The following methods work on any slice type.

ProcessSlice

Example

	var aSlice interface{}
	
	toolbox.ProcessSlice(aSlice, func(item interface{}) bool {
    		...
    		return true //to continue to next element return true
    })
	

ProcessSliceWithIndex

Example:

	var aSlice interface{}
	
	toolbox.ProcessSlice(aSlice, func(index int, item interface{}) bool {
    		...
    		return true //to continue to next element return true
    })
	

IndexSlice

Example:

    type Foo struct{
		id int
		name string
	}

	var aSlice = []Foo{ Foo{1, "A"}, Foo{2, "B"} }
	var indexedMap = make(map[int]Foo)
	
	toolbox.IndexSlice(aSlice, indexedMap, func(foo Foo) int {
		return foo.id
	})
	
	

CopySliceElements

Example:

   source := []interface{}{
   		"abc", "def", "cyz",
   	}
   	var target = make([]string, 0)
   	toolbox.CopySliceElements(source, &target)
	
	

FilterSliceElements

Example:

	source := []interface{}{
		"abc", "def", "cyz","adc",
	}
	var target = make([]string, 0)
	
	toolbox.FilterSliceElements(source, func(item string) bool {
		return strings.HasPrefix(item, "a") //this matches any elements starting with a
	}, &target)

HasSliceAnyElements

Example:

    source := []interface{}{
		"abc", "def", "cyz","adc",
	}
	toolbox.HasSliceAnyElements(source, "cyz")

SliceToMap

Example:

    var source = []Foo{ Foo{1, "A"}, Foo{2, "B"} }
	var target = make(map[int]string)
	toolbox.MakeMapFromSlice(source, target, func(foo Foo) int {
		return foo.id
	},
	func(foo Foo) string {
		return foo.name
	})
	

TransformSlice

Example:

type Product struct{ vendor, name string }
	products := []Product{
		Product{"Vendor1", "Product1"},
		Product{"Vendor2", "Product2"},
		Product{"Vendor1", "Product3"},
		Product{"Vendor1", "Product4"},
	}
	var vendors=make([]string, 0)
	toolbox.TransformSlice(products, &vendors, func(product Product) string {
		return product.vendor
	})
Map utilities

ProcessMap

The following methods work on any map type.

Example:

    var aMap interface{}
	toolbox.ProcessMap(aMap, func(key, value interface{}) bool {
    		...
    		return true //to continue to next element return true
    })

CopyMapEntries

Example:

    type Foo struct{id int;name string}
	
	source := map[interface{}]interface{} {
		1: Foo{1, "A"},
		2: Foo{2, "B"},
	}
	var target = make   (map[int]Foo)

	toolbox.CopyMapEntries(source, target)

MapKeysToSlice

Example:

    aMap := map[string]int {
		"abc":1,
		"efg":2,
	}
	var keys = make([]string, 0)
	toolbox.MapKeysToSlice(aMap, &keys)

GroupSliceElements

Example:

	type Product struct{vendor,name string}
    	products := []Product{
    		Product{"Vendor1", "Product1"},
    		Product{"Vendor2", "Product2"},
    		Product{"Vendor1", "Product3"},
    		Product{"Vendor1", "Product4"},
    	}
    
    	productsByVendor := make(map[string][]Product)
    	toolbox.GroupSliceElements(products, productsByVendor, func(product Product) string {
    		return product.vendor
    	})

SliceToMultimap

	type Product struct {
    		vendor, name string
    		productId    int
    	}
    
    	products := []Product{
    		Product{"Vendor1", "Product1", 1},
    		Product{"Vendor2", "Product2", 2},
    		Product{"Vendor1", "Product3", 3},
    		Product{"Vendor1", "Product4", 4},
    	}
    
    	productsByVendor := make(map[string][]int)
    	toolbox.SliceToMultimap(products, productsByVendor, func(product Product) string {
    		return product.vendor
    	},
    	func(product Product) int {
    		return product.productId
    	})

Converter && Conversion Utilities

Converter transforms, data between any compatible or incompatible data type including struct/basicType/map/slice/interface{} On top of that it supports custom tag to map field to target data type (i.e map)

    myStruct :=  //some struct ...
    myMap := make(map[string]interface{})
    converter := NewConverter(dateLayout, keyTag) 	
    err = converter.AssignConverted(&myMap, myStruct)
    err = converter.AssignConverted(myStruct, myMap) 

Struct Utilities

ScanStructMethods

Scan struct methods

    service := New()
    err = toolbox.ScanStructMethods(service, 1, func(method reflect.Method) error {
		fmt.Printf("%v\n", method.Name)
		return nil
	})

ProcessStruct

Scan struct fields

   service := New()
    err = toolbox.ProcessStruct(service,
        func(field reflect.StructField, value reflect.Value) error {
            fmt.Print(field.Type.Name)
            return nil
    })

Function Utilities

Time Utilities

DateFormatToLayout

Java date format style to go date layout conversion.

    dateLaout := toolbox.DateFormatToLayout("yyyy-MM-dd hh:mm:ss z")
    timeValue, err := time.Parse(dateLaout, "2016-02-22 12:32:01 UTC")

TimeAt

Provide dynamic semantic for creating time object

    
    tomorrow, err = TimeAt("tomorrow")//tomorrow in local timezone
    timeInUTC, err := TimeAt("2 days ago in UTC") //or 2DayAgoInUTC
    yesterdayUTC, err := TimeAt("yesterdayInUTC")//yesterday in UTC
    hoursAhead, err := TimeAt("50 hours ahead")

TimeDiff

Provide dynamic semantic for creating time object based on time dif


    lastyear, _ := time.Parse(DateFormatToLayout("yyyy-MM-dd"), "2017-01-01")
    ts1, e := TimeDiff(lastyear, "50 hours earlier")
    ts2, e := TimeDiff(lastyear, "3 days before in Poland")
	

DayElapsed


    t0, _ := time.Parse(DateFormatToLayout("yyyy-MM-dd hh:mm:ss"), "2017-01-01 12:00:00")
    dayElapsedInT0, err := ElapsedDay(t0) //0.5
	

ElapsedToday


    elapscedInLocalTz, err := ElapsedTodayInPct("")  
    elapscedInUTC, err := ElapsedToday("UTC")
	

RemainingToday


    elapscedInLocalTz, err := RemainingTodayInPct("")
    elapscedInUTC, err := RemainingToday("UTC")
	

Storage API

Storage API provides unified way of accessing local or remote storage system.

Example

    import (
    	"github.com/viant/toolbox/storage"
    	_ "github.com/viant/toolbox/storage/gs"	
    )
    
    
    destinationURL := "gs://myBucket/set1/content.gz"
    destinationCredentialFile = "gs-secret.json"
    storageService, err := storage.NewServiceForURL(destinationURL, destinationCredentialFile)

Macro

Tokenizer

ServiceRouter

This ServiceRouter provides simple WebService Endpoint abstractin and RESET Client utilities.

Take as example of a ReverseService defined as follow


type ReverseService interface {
        Reverse(values []int) []int 
}

type reverseService struct{}

func (r *reverseService) Reverse(values []int) []int {
	var result = make([]int, 0)
	for i := len(values) - 1; i >= 0; i-- {
		result = append(result, values[i])
	}

	return result
}

In order to define Endpoint for this service, define a server, a router with the service routes;



type Server struct {
    service ReverseService
    port string
}

func (s *Server) Start() {
    
    router := toolbox.NewServiceRouter(
		toolbox.ServiceRouting{
			HTTPMethod: "GET",
			URI:        "/v1/reverse/{ids}",
			Handler:    s.service.Reverse,
			Parameters: []string{"ids"}, 
		},
		toolbox.ServiceRouting{
			HTTPMethod: "POST",
			URI:        "/v1/reverse/",
			Handler:    s.service.Reverse,
			Parameters: []string{"ids"},
		})
		
        http.HandleFunc("/v1/", func(writer http.ResponseWriter, reader *http.Request) {
            err := router.Route(writer, reader)
            if err != nil {
                response.WriteHeader(http.StatusInternalServerError)
            }
        })
    
        fmt.Printf("Started test server on port %v\n", port)
        log.Fatal(http.ListenAndServe(":"+port, nil))
}

ServiceRouting parameters define handler parameters that can be extracted from URI, QueryString, or from Post Body (json payload) In addition two special parameter names are supported: @httpRequest, @httpResponseWriter to pass in request, and response object respectively.

The REST client utility invoking our reverse service may look as follow


               var result = make([]int, 0)
               err := toolbox.RouteToService("get", "http://127.0.0.1:8082/v1/reverse/1,7,3", nil, &result)
               //...
               err := toolbox.RouteToService("post", "http://127.0.0.1:8082/v1/reverse/", []int{1, 7, 3}, &result)

By default a service router uses reflection to call the matched routes handler, it is possible to avoid reflection overhead by providing the custom handler invoker.



var ReverseInvoker = func(serviceRouting *toolbox.ServiceRouting, request *http.Request, response http.ResponseWriter, uriParameters map[string]interface{}) error {
	var function = serviceRouting.Handler.(func(values []int) []int)
	idsParam := uriParameters["ids"]
	ids := idsParam.([]string)
	values := make([]int, 0)
	for _, item := range ids {
		values = append(values, toolbox.AsInt(item))
	}
	var result = function(values)
	err := toolbox.WriteServiceRoutingResponse(response, request, serviceRouting, result)
	if err != nil {
		return err
	}
	return nil
}

//...

 
        router := toolbox.NewServiceRouter(
		toolbox.ServiceRouting{
			HTTPMethod: "GET",
			URI:        "/v1/reverse/{ids}",
			Handler:    s.service.Reverse,
			Parameters: []string{"ids"},
			HandlerInvoker: ReverseInvoker,
		})
//...		
		

Decoder and Encoder
Decoder

This library defines DecoderFactory interface to delegate decoder creation, This library comes with standard JSON and UnMarshaler (protobuf) factory implementation.

Example

    factory :=toolbox.NewJsonDecoderFactory()
    ....
    
    decoder := factory.Create(reader)
    foo := &Foo{}
    err = decoder.Decode(foo)



    marshalerFactory := toolbox.NewUnMarshalerDecoderFactory()
    decoder := marshalerFactory.Create(reader)
    foo := &Foo{}
    err = decoder.Decode(foo)
Encoder

This library defines EncoderFactory interface to delegate encoder creation, This library comes with standard JSON and Marshaler (protobuf) factory implementation.

Example

        factory :=toolbox.NewJsonEncoderFactory()
        ....
        buffer := new(bytes.Buffer)
        
        
        decoder := factory.Create(buffer)
        err = decoder.Encode(foo)
    
    
    
        marshalerFactory := toolbox.NewMarshalerEncoderFactory()
        decoder := marshalerFactory.Create(buffer)
        err = decoder.Encode(foo)

Logger

This library provides a file logger implementation that optimizes writes. Log messages are queues until max queue size or flush frequency are met. On top of that Ctrl-C also forces immediate log messages flush to disk.

File template support java style time format to manage rotation on the file name level.

    logger, err := toolbox.NewFileLogger(toolbox.FileLoggerConfig{
		LogType:           "test",
		FileTemplate:      "/tmp/test[yyyyMMdd-hhmm].log",
		QueueFlashCount:   250,
		MaxQueueSize:      500,
		FlushFrequencyInMs: 2000,
		MaxIddleTimeInSec: 1,
	}, toolbox.FileLoggerConfig{
       		LogType:           "transaction",
       		FileTemplate:      "/tmp/transaction[yyyyMMdd-hhmm].log",
       		QueueFlashCount:   250,
       		MaxQueueSize:      500,
       		FlushFrequencyInMs:2000,
       		MaxIddleTimeInSec: 1,
       	},
	)

    logger.Log(&toolbox.LogMessage{
        MessageType: "test",
        Message:     message
    })
    
    logger.Log(&toolbox.LogMessage{
            MessageType: "transaction",
            Message:     message
        })

BatchLimiter

This library provides a batch limiter, that enables controling number of active go routines.


     var tasks []*Task
     var batchSize = 4
	 limiter:= toolbox.NewBatchLimiter(batchSize, len(tasks))
   	 for i, _ :=  range tasks {
            go func(task *Task) {
                    limiter.Acquire()
                    defer limiter.Done()
                    task.Run();
        	}(tasks[i])
	}
	limiter.Wait()

GoCover

GoCover

License

The source code is made available under the terms of the Apache License, Version 2, as stated in the file LICENSE.

Individual files may be made available under their own specific license, all compatible with Apache License, Version 2. Please see individual files for details.

Credits and Acknowledgements

Library Author: Adrian Witas

Contributors:

Documentation

Overview

Package toolbox - useful set of utilities/abstractions developed as part of datastore connectivity and testing (viant/dsc, viant/dsunit).

Index

Constants

View Source
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"
)
View Source
const (
	MethodGet     = "GET"
	MethodHead    = "HEAD"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodPatch   = "PATCH" // RFC 5789
	MethodDelete  = "DELETE"
	MethodOptions = "OPTIONS"
	MethodTrace   = "TRACE"
)
View Source
const (
	Now       = "now"
	Tomorrow  = "tomorrow"
	Yesterday = "yesterday"

	DurationWeek            = "week"
	DurationDay             = "day"
	DurationHour            = "hour"
	DurationMinute          = "minute"
	DurationMinuteAbbr      = "min"
	DurationSecond          = "second"
	DurationSecondAbbr      = "sec"
	DurationMillisecond     = "millisecond"
	DurationMillisecondAbbr = "ms"
	DurationMicrosecond     = "microsecond"
	DurationMicrosecondAbbr = "us"
	DurationNanosecond      = "nanosecond"
	DurationNanosecondAbbr  = "ns"
)

Variables

View Source
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

View Source
var DateFormatKeyword = "dateFormat"

DateFormatKeyword constant 'dateFormat' key

View Source
var DateLayoutKeyword = "dateLayout"

DateLayoutKeyword constant 'dateLayout' key

View Source
var DefaultConverter = NewConverter("", "name")

DefaultConverter represents a default data structure converter

View Source
var DefaultDateLayout = "2006-01-02 15:04:05.000"

DefaultDateLayout is set to 2006-01-02 15:04:05.000

View Source
var DefaultDecoderFactory = NewJSONDecoderFactory()

DefaultDecoderFactory - NewJSONDecoderFactory

View Source
var DefaultEncoderFactory = NewJSONEncoderFactory()

DefaultEncoderFactory - NewJSONEncoderFactory

View Source
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.

View Source
var FileSchema = "file://"

FileSchema file://

View Source
var TrueProvider = func(input interface{}) bool {
	return true
}
View Source
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

View Source
var YamlDefaultDecoderFactory = NewFlexYamlDecoderFactory()

YamlDefaultDecoderFactory - NewYamlDecoderFactory

View Source
var YamlDefaultEncoderFactory = NewYamlEncoderFactory()

YamlDefaultEncoderFactory - NewYamlEncoderFactory

Functions

func AsBoolean

func AsBoolean(value interface{}) bool

AsBoolean converts an input to bool.

func AsCompatibleFunctionParameters

func AsCompatibleFunctionParameters(function interface{}, parameters []interface{}) ([]interface{}, error)

AsCompatibleFunctionParameters takes incompatible function parameters and converts then into provided function signature compatible

func AsFloat

func AsFloat(value interface{}) float64

AsFloat converts an input to float.

func AsIndentJSONText

func AsIndentJSONText(source interface{}) (string, error)

AsIndentJSONText converts data structure int text JSON

func AsInt

func AsInt(value interface{}) int

AsInt converts an input to int.

func AsJSONText

func AsJSONText(source interface{}) (string, error)

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 or Ranger as []interface{}

func AsString

func AsString(input interface{}) string

AsString converts an input to string.

func AsTime

func AsTime(value interface{}, dateLayout string) *time.Time

AsTime converts an input to time, it takes time input, dateLaout as parameters.

func AsYamlText

func AsYamlText(source interface{}) (string, error)

AsYamlText converts data structure int text YAML

func AssertKind

func AssertKind(input interface{}, kind reflect.Kind, name string)

AssertKind checks if input is of the passed in kind, if not it panic with message including name

func AssertPointerKind

func AssertPointerKind(input interface{}, kind reflect.Kind, name string)

AssertPointerKind checks if input is a pointer of the passed in kind, if not it panic with message including name

func AssertTypeKind

func AssertTypeKind(dataType reflect.Type, kind reflect.Kind, name string)

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

func CallerDirectory(callerIndex int) string

CallerDirectory returns directory of caller source code directory

func CallerInfo

func CallerInfo(callerIndex int) (string, string, int)

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 CopyNonEmptyMapEntries

func CopyNonEmptyMapEntries(input, output interface{}) (err error)

CloneNonEmptyMap removes empty keys from map result

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

func CreateDirIfNotExist(dirs ...string) error

CreateDirIfNotExist creates directory if they do not exist

func DateFormatToLayout

func DateFormatToLayout(dateFormat string) string

DateFormatToLayout converts java date format https://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html#rfc822timezone into go date layout

func DefaultStructMetaFilter added in v0.10.0

func DefaultStructMetaFilter(ield reflect.StructField) bool

func DeleteEmptyKeys

func DeleteEmptyKeys(input interface{}) map[string]interface{}

DeleteEmptyKeys removes empty keys from map result

func DereferenceType

func DereferenceType(value interface{}) reflect.Type

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 DiscoverCaller

func DiscoverCaller(offset, maxDepth int, ignoreFiles ...string) (string, string, int)

DiscoverCaller returns the first matched caller info

func DiscoverCollectionValuesAndKind

func DiscoverCollectionValuesAndKind(values interface{}) ([]interface{}, reflect.Kind)

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

func DiscoverComponentType(input interface{}) reflect.Type

DiscoverComponentType returns type unwrapped from pointer, slice or map

func DiscoverTypeByKind

func DiscoverTypeByKind(input interface{}, expected reflect.Kind) reflect.Type

DiscoverTypeByKind returns unwrapped input type that matches expected kind, or panic if this is not possible

func DiscoverValueAndKind

func DiscoverValueAndKind(input string) (interface{}, reflect.Kind)

DiscoverValueAndKind discovers input kind, it applies checks of the following types: int, float, bool, string

func DiscoverValueByKind

func DiscoverValueByKind(input interface{}, expected reflect.Kind) reflect.Value

DiscoverValueByKind returns unwrapped input that matches expected kind, or panic if this is not possible

func Dump

func Dump(data interface{})

Dump prints passed in data as JSON

func DumpIndent

func DumpIndent(data interface{}, removeEmptyKeys bool) error

DumpIndent prints passed in data as indented JSON

func ElapsedDay added in v0.4.2

func ElapsedDay(dateTime time.Time) float64

ElapsedDay returns elapsed pct for passed in day (second elapsed that day over 24 hours)

func ElapsedToday added in v0.4.2

func ElapsedToday(tz string) (float64, error)

ElapsedToday returns elapsed today time percent, it takes optionally timezone

func ExpandFileTemplate

func ExpandFileTemplate(template string) string

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

func ExtractMimeType(file string) string

ExtractMimeType extracts mime type by extension

func ExtractURIParameters

func ExtractURIParameters(templateURI, requestURI string) (map[string]string, bool)

ExtractURIParameters parses URIs to extract {<param>} defined in templateURI from requestURI, it returns extracted parameters and flag if requestURI matched templateURI

func FileExists

func FileExists(filename string) bool

FileExists checks if file exists

func Filename

func Filename(filename string) string

Filename reformat file name

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

func GetFuncSignature(function interface{}) []reflect.Type

GetFuncSignature returns a function signature

func GetFunction

func GetFunction(owner interface{}, name string) (interface{}, error)

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

func GetTimeLayout(input interface{}) string

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

func HasTimeLayout(input interface{}) bool

HasTimeLayout checks if dateLayout can be taken from the passed in setting map

func IgnoreUnexportedFields added in v0.10.0

func IgnoreUnexportedFields(structField *StructField) bool

Handler ignoring unexported fields

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

func IsASCIIText(candidate string) bool

IsASCIIText return true if supplied string does not have binary data

func IsBool

func IsBool(input interface{}) bool

IsBool returns true if input is a boolean

func IsCompleteJSON

func IsCompleteJSON(candidate string) bool

IsCompleteJSON returns true if supplied represent complete JSON

func IsEOFError

func IsEOFError(err error) bool

IsEOFError returns true if io.EOF

func IsFloat

func IsFloat(input interface{}) bool

IsFloat returns true if input is a float

func IsFunc

func IsFunc(input interface{}) bool

IsFunc returns true if input is a funct

func IsInt

func IsInt(input interface{}) bool

IsInt returns true if input is an int

func IsMap

func IsMap(input interface{}) bool

IsMap returns true if input is a map

func IsNewLineDelimitedJSON

func IsNewLineDelimitedJSON(candidate string) bool

IsNewLineDelimitedJSON returns true if supplied content is multi line delimited JSON

func IsNilPointerError

func IsNilPointerError(err error) bool

IsNilPointerError returns true if error is nil pointer

func IsNotFoundError added in v0.6.3

func IsNotFoundError(err error) bool

IsNotFoundError checks is supplied error is NotFoundError type

func IsNumber added in v0.10.0

func IsNumber(input interface{}) bool

IsNumber returns true if type is either float or int

func IsPointer

func IsPointer(input interface{}) bool

IsPointer returns true if input is a pointer

func IsPrintText

func IsPrintText(candidate string) bool

IsPrintText return true if all candidate characters are printable (unicode.IsPrintText)

func IsSlice

func IsSlice(input interface{}) bool

IsSlice returns true if input is a map

func IsString

func IsString(input interface{}) bool

IsString returns true if input is a string

func IsStruct

func IsStruct(input interface{}) bool

IsStruct returns true if input is a map

func IsTime

func IsTime(input interface{}) bool

IsTime returns true if input is a time

func IsValueOfKind

func IsValueOfKind(input interface{}, kind reflect.Kind) bool

IsValueOfKind returns true if passed in input is of supplied kind.

func IsZero

func IsZero(input interface{}) bool

IsZero returns true if input is a zeroable

func JSONToInterface

func JSONToInterface(source interface{}) (interface{}, error)

JSONToInterface converts JSON source to an interface (either map or slice)

func JSONToMap

func JSONToMap(source interface{}) (map[string]interface{}, error)

JSONToMap converts JSON source into map

func JSONToSlice

func JSONToSlice(source interface{}) ([]interface{}, error)

JSONToSlice converts JSON source into slice

func JoinAsString

func JoinAsString(slice interface{}, separator string) string

JoinAsString joins all items of a slice, with separator, it takes any slice as argument,

func MakeMap

func MakeMap(text string, valueSeparator string, itemSeparator string) map[string]interface{}

MakeMap creates a mapstring]interface{} from string,

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

func MakeStringMap(text string, valueSeparator string, itemSeparator string) map[string]string

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 NewBytes

func NewBytes(input []byte) []byte

NewBytes copies from input

func NewBytesBufferPool

func NewBytesBufferPool(poolSize, bufferSize int) httputil.BufferPool

NewBytesBufferPool returns new httputil.BufferPool pool.

func NewDuration

func NewDuration(value int, unit string) (time.Duration, error)

NewDuration returns a durationToken for supplied value and time unit, 3, "second"

func NewFieldSettingByKey

func NewFieldSettingByKey(aStruct interface{}, key string) map[string](map[string]string)

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 NewIllegalTokenError

func NewIllegalTokenError(message string, expected []int, position int, found *Token) error

NewIllegalTokenError create a new illegal token error

func NewLineDelimitedJSON

func NewLineDelimitedJSON(candidate string) ([]interface{}, error)

NewLineDelimitedJSON returns JSON for supplied multi line JSON

func NewNilPointerError

func NewNilPointerError(message string) error

NewNilPointerError creates a new nil pointer error

func NormalizeKVPairs added in v0.5.0

func NormalizeKVPairs(source interface{}) (interface{}, error)

NormalizeKVPairs converts slice of KV paris into a map, and map[interface{}]interface{} to map[string]interface{}

func OpenFile

func OpenFile(filename string) (*os.File, error)

OpenFile open file converting path to elements and rebuling path safety with path.Join

func Pairs

func Pairs(params ...interface{}) map[string]interface{}

Pairs returns map for pairs.

func ParseTime

func ParseTime(input, layout string) (time.Time, error)

ParseTime parses time, adjusting date layout to length of input

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(source interface{}, handler func(key, value interface{}) bool) error

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

func ProcessSliceWithIndex(slice interface{}, handler func(index int, item interface{}) bool)

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

func QueryBoolValue(u *url.URL, name string, defaultValue bool) bool

QueryBoolValue returns query value for passed in url's name or default value

func QueryIntValue

func QueryIntValue(u *url.URL, name string, defaultValue int) int

QueryIntValue returns query value for passed in url's name or default value

func QueryValue

func QueryValue(u *url.URL, name, defaultValue string) string

QueryValue returns query value for passed in url's name or default value

func ReclassifyNotFoundIfMatched added in v0.6.3

func ReclassifyNotFoundIfMatched(err error, URL string) error

ReclassifyNotFoundIfMatched reclassify error if not found

func RemainingToday added in v0.4.2

func RemainingToday(tz string) (float64, error)

RemainingToday returns remaining today time percent, it takes optionally timezone

func RemoveFileIfExist

func RemoveFileIfExist(filenames ...string) error

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

func RouteToService(method, url string, request, response interface{}) (err error)

RouteToService calls web service url, with passed in json request, and encodes http json response into passed response

func ScanStructMethods added in v0.7.0

func ScanStructMethods(structOrItsType interface{}, depth int, handler func(method reflect.Method) error) error

ScanStructFunc scan supplied struct methods

func SetSliceValue

func SetSliceValue(slice interface{}, index int, value interface{})

SetSliceValue sets value at slice index

func SetStructMetaFilter added in v0.10.0

func SetStructMetaFilter(filter StructMetaFilter) error

SetStructMetaFilter sets struct meta filter

func SetUnexportedFieldHandler added in v0.10.0

func SetUnexportedFieldHandler(handler UnexportedFieldHandler) error

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

func SortStrings(source []string) []string

SortStrings creates a new copy of passed in slice and sorts it.

func TerminatedSplitN added in v0.6.3

func TerminatedSplitN(text string, fragmentCount int, terminator string) []string

TerminatedSplitN split supplied text into n fragmentCount, each terminated with supplied terminator

func TimeAt

func TimeAt(offsetExpression string) (*time.Time, error)

TimeAt returns time of now supplied offsetExpression, this function uses TimeDiff

func TimeDiff

func TimeDiff(base time.Time, expression string) (*time.Time, error)

TimeDiff returns time for supplied base time and literal, the supported literal now, yesterday, tomorrow, or the following template:

  • [timeValueToken] durationToken past_or_future_modifier [IN tz]

where time modifier can be any of the following: "onward", "ahead", "after", "later", or "past", "ago", "before", "earlier", "in the future", "in the past") )

func TimestampToString

func TimestampToString(dateFormat string, unixTimestamp, unixNanoTimestamp int64) string

TimestampToString formats timestamp to passed in java style date format

func ToBoolean

func ToBoolean(value interface{}) (bool, error)

ToBoolean converts an input to bool.

func ToFloat

func ToFloat(value interface{}) (float64, error)

ToFloat converts an input to float or error

func ToInt

func ToInt(value interface{}) (int, error)

ToInt converts input value to int or error

func ToMap

func ToMap(source interface{}) (map[string]interface{}, error)

ToMap converts underlying map/struct/[]KV as map[string]interface{}

func ToTime

func ToTime(value interface{}, dateLayout string) (*time.Time, error)

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 TryDiscoverTypeByKind added in v0.4.2

func TryDiscoverTypeByKind(input interface{}, expected reflect.Kind) (reflect.Type, error)

TryDiscoverTypeByKind returns unwrapped input type that matches expected kind, or error

func TryDiscoverValueByKind added in v0.7.0

func TryDiscoverValueByKind(input interface{}, expected reflect.Kind) (reflect.Value, error)

TryDiscoverValueByKind returns unwrapped input that matches expected kind, or panic if this is not possible

func URLBase

func URLBase(URL string) string

URLBase returns base URL

func URLPathJoin

func URLPathJoin(baseURL, path string) string

URLPathJoin joins URL paths

func URLSplit

func URLSplit(URL string) (string, string)

URLSplit returns URL with parent path and resource name

func URLStripPath

func URLStripPath(URL string) string

URLStripPath removes path from URL

func UnwrapValue

func UnwrapValue(value *reflect.Value) interface{}

UnwrapValue returns value

func WaitTimeout

func WaitTimeout(wg *sync.WaitGroup, duration time.Duration) bool

WaitGroup that waits with a timeout Returns true if timeout exceeded and false if there was no timeout

func WriteServiceRoutingResponse

func WriteServiceRoutingResponse(response http.ResponseWriter, request *http.Request, serviceRouting *ServiceRouting, result interface{}) error

WriteServiceRoutingResponse writes service router response

Types

type AnyJSONType added in v0.7.0

type AnyJSONType string

func (*AnyJSONType) MarshalJSON added in v0.7.0

func (s *AnyJSONType) MarshalJSON() ([]byte, error)

func (*AnyJSONType) UnmarshalJSON added in v0.7.0

func (s *AnyJSONType) UnmarshalJSON(b []byte) error

func (AnyJSONType) Value added in v0.7.0

func (s AnyJSONType) Value() (interface{}, error)

Value returns string or string slice value

type BatchLimiter

type BatchLimiter struct {
	Mutex *sync.RWMutex
	// contains filtered or unexported fields
}

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

type BodyMatcher struct {
	Begin string
	End   string
}

LiteralMatcher represents a matcher that finds any literals in the input

func (*BodyMatcher) Match

func (m *BodyMatcher) Match(input string, offset int) (matched int)

Match matches a literal in the input, it returns number of character matched.

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

func (*ByteWriterAt) WriteAt

func (w *ByteWriterAt) WriteAt(p []byte, offset int64) (n int, err error)

WriteAt returns number of written bytes or error

type CharactersMatcher

type CharactersMatcher struct {
	Chars string //characters to be matched
}

CharactersMatcher represents a matcher, that matches any of Chars.

func (CharactersMatcher) Match

func (m CharactersMatcher) Match(input string, offset int) int

Match matches any characters defined in Chars in the input, returns 1 if character has been matched

type ContentTypeAccessor

type ContentTypeAccessor interface {
	GetContentType() string
}

ContentTypeAccessor server side response accessor

type ContentTypeMutator

type ContentTypeMutator interface {
	SetContentType(contentType string)
}

ContentTypeMutator client side reponse optional interface

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.

func NewContext

func NewContext() Context

NewContext creates a new context

type Converter

type Converter struct {
	DateLayout   string
	MappedKeyTag string
}

Converter represets data converter, it converts incompatibe data structure, like map and struct, string and time, *string to string, etc.

func NewColumnConverter

func NewColumnConverter(dateLayout string) *Converter

NewColumnConverter create a new converter, that has ability to convert map to struct using column mapping

func NewConverter

func NewConverter(dateLayout, keyTag string) *Converter

NewConverter create a new converter, that has ability to convert map to struct, it uses keytag to identify source and dest of fields/keys

func (*Converter) AssignConverted

func (c *Converter) AssignConverted(target, source interface{}) error

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 NewFlexYamlDecoderFactory

func NewFlexYamlDecoderFactory() DecoderFactory

NewFlexYamlDecoderFactory create a new yaml 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

type DelimitedRecord struct {
	Columns   []string
	Delimiter string
	Record    map[string]interface{}
}

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 EOFMatcher

type EOFMatcher struct {
}

EOFMatcher represents end of input matcher

func (EOFMatcher) Match

func (m EOFMatcher) Match(input string, offset int) int

Match returns 1 if end of input has been reached otherwise 0

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
	ComponentType      string
	IsPointerComponent bool
	KeyTypeName        string
	ValueTypeName      string
	TypePackage        string
	IsAnonymous        bool
	IsMap              bool
	IsChannel          bool
	IsSlice            bool
	IsPointer          bool
	Tag                string
	Comment            string
}

FieldInfo represents a filed info

func NewFieldInfo

func NewFieldInfo(field *ast.Field) *FieldInfo

NewFieldInfo creates a new field info.

type FileInfo

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

FileInfo represent hold definition about all defined types and its receivers in a file

func NewFileInfo

func NewFileInfo(basePath, packageName, filename string, fileSet *token.FileSet) *FileInfo

Visit creates a new file info.

func (*FileInfo) HasType

func (f *FileInfo) HasType(name string) bool

HasType returns truc if struct info is defined in a file

func (*FileInfo) Type

func (f *FileInfo) Type(name string) *TypeInfo

Type returns a type info for passed in name

func (*FileInfo) Types

func (f *FileInfo) Types() []*TypeInfo

Type returns all struct info

func (*FileInfo) Visit

func (v *FileInfo) Visit(node ast.Node) ast.Visitor

Visit visits ast node to extract struct details from the passed file

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) Type

func (f *FileSetInfo) Type(name string) *TypeInfo

TypeInfo returns type info for passed in type 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

func (IdMatcher) Match

func (m IdMatcher) Match(input string, offset int) int

Match matches a literal in the input, it returns number of character matched.

type IllegalTokenError

type IllegalTokenError struct {
	Illegal  *Token
	Message  string
	Expected []int
	Position int
}

IllegalTokenError represents illegal token error

func (*IllegalTokenError) Error

func (e *IllegalTokenError) Error() string

type IntMatcher

type IntMatcher struct{}

IntMatcher represents a matcher that finds any int in the input

func (IntMatcher) Match

func (m IntMatcher) Match(input string, offset int) int

Match matches a literal in the input, it returns number of character matched.

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

type KeywordMatcher struct {
	Keyword       string
	CaseSensitive bool
}

KeywordMatcher represents a keyword matcher

func (KeywordMatcher) Match

func (m KeywordMatcher) Match(input string, offset int) (matched int)

Match matches keyword in the input, it returns number of character matched.

type KeywordsMatcher

type KeywordsMatcher struct {
	Keywords      []string
	CaseSensitive bool
}

KeywordsMatcher represents a matcher that finds any of specified keywords in the input

func (KeywordsMatcher) Match

func (m KeywordsMatcher) Match(input string, offset int) (matched int)

Match matches any specified keyword, it returns number of character matched.

type LiteralMatcher

type LiteralMatcher struct{}

LiteralMatcher represents a matcher that finds any literals in the input

func (LiteralMatcher) Match

func (m LiteralMatcher) Match(input string, offset int) int

Match matches a literal in the input, it returns number of character matched.

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) Close

func (s *LogStream) Close()

Close closes 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.

func NewBodyMatcher

func NewBodyMatcher(begin, end string) Matcher

NewBodyMatcher creates a new body matcher

func NewCharactersMatcher

func NewCharactersMatcher(chars string) Matcher

NewCharactersMatcher creates a new character matcher

func NewCustomIdMatcher

func NewCustomIdMatcher(allowedChars ...string) Matcher

NewCustomIdMatcher creates new custom matcher

func NewIntMatcher

func NewIntMatcher() Matcher

NewIntMatcher returns a new integer matcher

func NewKeywordsMatcher

func NewKeywordsMatcher(caseSensitive bool, keywords ...string) Matcher

NewKeywordsMatcher returns a matcher for supplied keywords

func NewRemainingSequenceMatcher

func NewRemainingSequenceMatcher() Matcher

Creates a matcher that matches all remaining input

func NewSequenceMatcher

func NewSequenceMatcher(terminators ...string) Matcher

NewSequenceMatcher creates a new matcher that finds all sequence until find at least one of the provided terminators

func NewTerminatorMatcher

func NewTerminatorMatcher(terminators ...string) Matcher

NewTerminatorMatcher creates a new matcher that finds any sequence until find at least one of the provided terminators

type NilPointerError

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

NilPointerError represents nil pointer error

func (*NilPointerError) Error

func (e *NilPointerError) Error() string

Error returns en error

type NotFoundError added in v0.6.3

type NotFoundError struct {
	URL string
}

NotFoundError represents not found error

func (*NotFoundError) Error added in v0.6.3

func (e *NotFoundError) Error() string

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

func NewComparablePredicate(operator string, leftOperand interface{}) Predicate

NewComparablePredicate create a new comparable predicate for =, !=, >=, <=

func NewInPredicate

func NewInPredicate(values ...interface{}) Predicate

NewInPredicate creates a new IN predicate

func NewLikePredicate

func NewLikePredicate(matching string) Predicate

NewLikePredicate create a new like predicate

func NewNilPredicate

func NewNilPredicate() Predicate

NewNilPredicate returns a new nil predicate

func NewWithinPredicate

func NewWithinPredicate(baseTime time.Time, deltaInSeconds int, dateLayout string) Predicate

NewWithinPredicate returns new NewWithinPredicate predicate, it takes base time, delta in second, and dateLayout

type Ranger

type Ranger interface {
	Range(func(item interface{}) (bool, error)) error
}

Ranger represents an abstraction that has ability range over collection item

type SequenceMatcher

type SequenceMatcher struct {
	Terminators   []string
	CaseSensitive bool
	// contains filtered or unexported fields
}

SequenceMatcher represents a matcher that finds any sequence until find provided terminators

func (*SequenceMatcher) Match

func (m *SequenceMatcher) Match(input string, offset int) int

Match matches a literal in the input, it returns number of character matched.

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 StatucCodeAccessor

type StatucCodeAccessor interface {
	GetStatusCode() int
}

StatucCodeAccessor server side response accessor

type StatucCodeMutator

type StatucCodeMutator interface {
	SetStatusCode(code int)
}

StatucCodeMutator client side reponse optional interface

type StructField added in v0.10.0

type StructField struct {
	Owner reflect.Value
	Value reflect.Value
	Type  reflect.StructField
}

StructField represents a struct field

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 StructMeta

type StructMeta struct {
	Type string

	Fields       []*StructFieldMeta `json:"fields,omitempty"`
	Dependencies []*StructMeta      `json:"dependencies,omitempty"`
	// contains filtered or unexported fields
}

StructMeta represents struct meta details

func GetStructMeta

func GetStructMeta(source interface{}) *StructMeta

GetStructMeta returns struct meta

func (*StructMeta) Message added in v0.10.0

func (m *StructMeta) Message() map[string]interface{}

type StructMetaFilter added in v0.10.0

type StructMetaFilter func(field reflect.StructField) bool

StructMetaFilter

type Token

type Token struct {
	Token   int
	Matched string
}

Token a matchable input

func ExpectToken

func ExpectToken(tokenizer *Tokenizer, errorMessage string, candidates ...int) (*Token, error)

ExpectToken returns the matched token or error

func ExpectTokenOptionallyFollowedBy

func ExpectTokenOptionallyFollowedBy(tokenizer *Tokenizer, first int, errorMessage string, second ...int) (*Token, error)

ExpectTokenOptionallyFollowedBy returns second matched token or error if first and second group was not matched

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.

func (*Tokenizer) Next

func (t *Tokenizer) Next(candidate int) *Token

Next tries to match a candidate, it returns token if imatching is successful.

func (*Tokenizer) Nexts

func (t *Tokenizer) Nexts(candidates ...int) *Token

Nexts matches the first of the candidates

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 TypeInfo

type TypeInfo struct {
	Name                   string
	Package                string
	FileName               string
	Comment                string
	IsSlice                bool
	IsStruct               bool
	IsDerived              bool
	ComponentType          string
	IsPointerComponentType bool
	Derived                string
	Settings               map[string]string
	// contains filtered or unexported fields
}

TypeInfo represents a struct info

func NewTypeInfo

func NewTypeInfo(name string) *TypeInfo

NewTypeInfo creates a new struct info

func (*TypeInfo) AddFields

func (s *TypeInfo) AddFields(fields ...*FieldInfo)

AddFields appends fileds to structinfo

func (*TypeInfo) AddReceivers

func (s *TypeInfo) AddReceivers(receivers ...*FunctionInfo)

AddReceivers adds receiver for the struct

func (*TypeInfo) Field

func (s *TypeInfo) Field(name string) *FieldInfo

Field returns filedinfo for supplied file name

func (*TypeInfo) Fields

func (s *TypeInfo) Fields() []*FieldInfo

Fields returns all fields

func (*TypeInfo) HasField

func (s *TypeInfo) HasField(name string) bool

HasField returns true if struct has passed in field.

func (*TypeInfo) HasReceiver

func (s *TypeInfo) HasReceiver(name string) bool

HasReceiver returns true if receiver is defined for struct

func (*TypeInfo) Receiver

func (s *TypeInfo) Receiver(name string) *FunctionInfo

Receiver returns receiver for passed in name

func (*TypeInfo) Receivers

func (s *TypeInfo) Receivers() []*FunctionInfo

Receivers returns struct functions

type UnMarshaler

type UnMarshaler interface {
	//Unmarshal converts a struct to bytes
	Unmarshal(data []byte) error
}

UnMarshaler represent an struct that can be converted to bytes

type UnexportedFieldHandler added in v0.10.0

type UnexportedFieldHandler func(structField *StructField) bool

UnexportedFieldHandler represents unexported field handler

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

type Zeroable

type Zeroable interface {
	//IsZero returns true, if value of object was zeroed.
	IsZero() bool
}

Zeroable represents object that can call IsZero

Directories

Path Synopsis
udf
aws
gs
s3
scp

Jump to

Keyboard shortcuts

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