goutils

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

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 4 Imported by: 47

README

golang + Utilities = goutils

goutils (Golang UTILitieS) is a Golang implementation of some functions and data types to help other libraries.
You can see an extended doc in godocs.

Install it writing in terminal:

go get github.com/fmorenovr/goutils

Example:

If you wan to compare different interfaces with an Integer parse:

  var a, b interface{}
  a = 2
  b = 5
  goutils.IntComparator(a, b)
  // this should return 1 if a>b
  // this should return -1 if a<b
  // this should return 0 if a=b

Or define your own comparator function:

  // supose that this is your struct
  type MyDataType struct{
    ID int
    name string
  }

  // your comparator, you cna use this function as TypeComparator type function
  func MyComparator(a, b interface{}) int {
    AaAsserted := a.(MyDataType)
    bAsserted := b.(MyDataType)
    switch {
      case aAsserted.ID > bAsserted.ID:
        return 1
      case aAsserted.ID < bAsserted.ID:
        return -1
      default:
        return 0
    }
  }

Documentation

Overview

goUtils is a implementation of some functions and data types to help other libraries.

read more in Readme.md file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteComparator

func ByteComparator(a, b interface{}) int

Compare byte

func ByteOperator

func ByteOperator(a, b interface{}, op string) interface{}

Operate byte

func Float32Comparator

func Float32Comparator(a, b interface{}) int

Compare float32

func Float32Operator

func Float32Operator(a, b interface{}, op string) interface{}

Operate float32

func Float64Comparator

func Float64Comparator(a, b interface{}) int

Compare float64

func Float64Operator

func Float64Operator(a, b interface{}, op string) interface{}

Operate float64

func Int16Comparator

func Int16Comparator(a, b interface{}) int

Compare int16

func Int16Operator

func Int16Operator(a, b interface{}, op string) interface{}

Operate int16

func Int32Comparator

func Int32Comparator(a, b interface{}) int

Compare int32

func Int32Operator

func Int32Operator(a, b interface{}, op string) interface{}

Operate int32

func Int64Comparator

func Int64Comparator(a, b interface{}) int

Compare int64

func Int64Operator

func Int64Operator(a, b interface{}, op string) interface{}

Operate int64

func Int8Comparator

func Int8Comparator(a, b interface{}) int

Compare int8

func Int8Operator

func Int8Operator(a, b interface{}, op string) interface{}

Operate int8

func IntComparator

func IntComparator(a, b interface{}) int

Compare int

func IntOperator

func IntOperator(a, b interface{}, op string) interface{}

Operate int

func RuneComparator

func RuneComparator(a, b interface{}) int

Compare rune (char with int32)

func RuneOperator

func RuneOperator(a, b interface{}, op string) interface{}

Operate rune (char with int32)

func StringComparator

func StringComparator(a, b interface{}) int

Compare strings

func StringOperator

func StringOperator(a, b interface{}, op string) interface{}

Operate strings

func TimeComparator

func TimeComparator(a, b interface{}) int

Compare Time

func ToBool

func ToBool(value interface{}) bool

ToBool converts a value to bool

func ToFloat32

func ToFloat32(value interface{}) float32

ToFloat32 converts a value to float32.

func ToFloat64

func ToFloat64(value interface{}) float64

ToFloat64 converts a value to float64.

func ToInt

func ToInt(value interface{}) int

ToInt converts a value to int.

func ToInt16

func ToInt16(value interface{}) int16

ToInt16 converts a value to int16.

func ToInt32

func ToInt32(value interface{}) int32

ToInt32 converts a value to int32.

func ToInt64

func ToInt64(value interface{}) int64

ToInt64 converts a value to int64.

func ToInt8

func ToInt8(value interface{}) int8

ToInt8 converts a value to int8.

func ToString

func ToString(value interface{}) string

ToString converts a value to string.

func ToUInt

func ToUInt(value interface{}) uint

ToUInt converts a value to uint.

func ToUInt16

func ToUInt16(value interface{}) uint16

ToUInt16 converts a value to uint16.

func ToUInt32

func ToUInt32(value interface{}) uint32

ToUInt32 converts a value to uint32.

func ToUInt64

func ToUInt64(value interface{}) uint64

ToUInt64 converts a value to uint64.

func ToUInt8

func ToUInt8(value interface{}) uint8

ToUInt8 converts a value to uint8.

func UInt16Comparator

func UInt16Comparator(a, b interface{}) int

Compare uint16

func UInt16Operator

func UInt16Operator(a, b interface{}, op string) interface{}

Operate uint16

func UInt32Comparator

func UInt32Comparator(a, b interface{}) int

Compare uint32

func UInt32Operator

func UInt32Operator(a, b interface{}, op string) interface{}

Operate uint32

func UInt64Comparator

func UInt64Comparator(a, b interface{}) int

Compare uint64

func UInt64Operator

func UInt64Operator(a, b interface{}, op string) interface{}

Operate uint64

func UInt8Comparator

func UInt8Comparator(a, b interface{}) int

Compare uint8

func UInt8Operator

func UInt8Operator(a, b interface{}, op string) interface{}

Operate uint8

func UIntComparator

func UIntComparator(a, b interface{}) int

Compare uint

func UIntOperator

func UIntOperator(a, b interface{}, op string) interface{}

Operate uint

Types

type Container

type Container interface {
	IsEmpty() bool
	Size() int
	Clear()
	Values() []interface{}
}

Principal container description for Data Structures

type EnumerableIndex

type EnumerableIndex interface {
	Each(func(index int, value interface{}))

	Any(func(index int, value interface{}) bool) bool
	All(func(index int, value interface{}) bool) bool
	Find(func(index int, value interface{}) bool) (int, interface{})
}

Functions for Ordered Containers that index doesnt work in these values

type EnumerableKey

type EnumerableKey interface {
	Each(func(key interface{}, value interface{}))

	Any(func(key interface{}, value interface{}) bool) bool
	All(func(key interface{}, value interface{}) bool) bool
	Find(func(key interface{}, value interface{}) bool) (interface{}, interface{})
}

Functions for Ordered Containers that index doesnt work in these key/values pairs

type IteratorIndex

type IteratorIndex interface {
	Next() bool
	Value() interface{}
	Index() int
	Begin()
	First() bool
}

Iterator to browse with index

type IteratorKey

type IteratorKey interface {
	Next() bool
	Value() interface{}
	Key() interface{}
	Begin()
	First() bool
}

Iterator to browse with key-value pairs.

type JSONDeserializer

type JSONDeserializer interface {
	FromJSON([]byte) error
}

Read JSON data

type JSONSerializer

type JSONSerializer interface {
	ToJSON() ([]byte, error)
}

Return JSON format

type ReverseIteratorIndex

type ReverseIteratorIndex interface {
	Prev() bool
	End()
	Last() bool
	IteratorIndex
}

ReverseIterator to browse with index

type ReverseIteratorKey

type ReverseIteratorKey interface {
	Prev() bool
	End()
	Last() bool
	IteratorKey
}

ReverseIterator to browse with key-value pairs.

type TypeComparator

type TypeComparator func(a, b interface{}) int

type TypeOperator

type TypeOperator func(a, b interface{}, op string) interface{}

Operate a,b:

Jump to

Keyboard shortcuts

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