util

package
v0.0.0-...-3f54671 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Examples

Constants

View Source
const (
	TemplateBeginDelimiter = "{"
	TemplateEndDelimiter   = "}"
)
View Source
const (
	DictionaryValueNotFound = DictionaryValue(-1)
)
View Source
const (
	EnvTemplateVar = "{env}"
)

Variables

This section is empty.

Functions

func Copy

func Copy(i any) any

Copy - return a copy of an interface{}, this will dereference a pointer.

func ExpandTemplate

func ExpandTemplate(t string, lookup VariableLookup) (string, error)

func FmtTimestamp

func FmtTimestamp(t time.Time) string
Example
s := FmtTimestamp(time.Now())

fmt.Printf("Timestamp : %v\n", s)
Output:

func IsNil

func IsNil(a any) bool

IsNil - determine if the interface{} holds is nil

Example
var i any

fmt.Printf("Nil any : %v\n", IsNil(i))
fmt.Printf("Wrapped nil Nil pointer : %v\n", IsNil(i))
Output:

Nil any : true
Wrapped nil Nil pointer : true

func IsNillable

func IsNillable(a any) bool

func IsPointer

func IsPointer(a any) bool
Example
var i any
var s string
var data = testStruct{}
var count int
var bytes []byte

fmt.Printf("any : %v\n", IsPointer(i))
fmt.Printf("int : %v\n", IsPointer(count))
fmt.Printf("int * : %v\n", IsPointer(&count))
fmt.Printf("string : %v\n", IsPointer(s))
fmt.Printf("string * : %v\n", IsPointer(&s))
fmt.Printf("struct : %v\n", IsPointer(data))
fmt.Printf("struct * : %v\n", IsPointer(&data))
fmt.Printf("[]byte : %v\n", IsPointer(bytes))
//fmt.Printf("Struct * : %v\n", IsPointer(&data))
Output:

any : false
int : false
int * : true
string : false
string * : true
struct : false
struct * : true
[]byte : false

func IsPointerType

func IsPointerType(a any) bool

func IsSerializable

func IsSerializable(i any) bool

IsSerializable - determine if any can be serialized

func MapSubset

func MapSubset(keys []string, m map[string]string) map[string]string

func SimpleHash

func SimpleHash(s string) uint32

func TrimDoubleSpace

func TrimDoubleSpace(s string) string
Example
s := "' this is an example of do  uble spaces  '"

fmt.Printf("String : %v\n", TrimDoubleSpace(s))
Output:

String : ' this is an example of do uble spaces '

Types

type DictionaryValue

type DictionaryValue int32

type InvertedDictionary

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

InvertedDictionary - used for inverted content, where key = string, value = id. // The im is used for normal lookups key = id, value = string

Example
dict := CreateInvertedDictionary()
fmt.Printf("Empty : %v\n", dict.IsEmpty())
val := dict.Lookup("")
fmt.Printf("Lookup [''] : %v\n\n", val)

val = dict.Add("")
fmt.Printf("Add [''] : %v\n", val)
fmt.Printf("Empty : %v\n", dict.IsEmpty())
val = dict.Lookup("")
fmt.Printf("Lookup [''] : %v\n\n", val)

val = dict.Add("new-key")
fmt.Printf("Add [new-key] : %v\n", val)
val = dict.Lookup("new-key")
fmt.Printf("Lookup [new-key] : %v\n\n", val)

val = dict.Add("new-key2")
fmt.Printf("Add [new-key2] : %v\n", val)
val = dict.Lookup("new-key2")
fmt.Printf("Lookup [new-key2] : %v\n\n", val)

var found = false
var val2 string
val2, found = dict.InverseLookup(1)
fmt.Printf("LookupKey [1] : %v %v\n\n", val2, found)

val2, found = dict.InverseLookup(2)
fmt.Printf("LookupKey [2] : %v %v\n\n", val2, found)

val2, found = dict.InverseLookup(3)
fmt.Printf("LookupKey [3] : %v %v\n\n", val2, found)
Output:

Empty : true
Lookup [''] : -1

Add [''] : 0
Empty : false
Lookup [''] : 0

Add [new-key] : 1
Lookup [new-key] : 1

Add [new-key2] : 2
Lookup [new-key2] : 2

LookupKey [1] : new-key true

LookupKey [2] : new-key2 true

LookupKey [3] :  false

func CreateInvertedDictionary

func CreateInvertedDictionary() *InvertedDictionary

func (*InvertedDictionary) Add

func (*InvertedDictionary) InverseLookup

func (d *InvertedDictionary) InverseLookup(value DictionaryValue) (string, bool)

func (*InvertedDictionary) IsEmpty

func (d *InvertedDictionary) IsEmpty() bool

func (*InvertedDictionary) Lookup

func (d *InvertedDictionary) Lookup(key string) DictionaryValue

type List

type List map[any]struct{}
Example
package main

import (
	"fmt"
)

func main() {
	uri := "www.google.com/search"
	links := make(List)

	links.Add(uri)
	fmt.Printf("Test - {Added} : %v\n", links)

	fmt.Printf("Test - {Is Empty} : %v\n", links.IsEmpty())

	fmt.Printf("Test - {Item} : %v\n", links[uri])

	fmt.Printf("Test - {Contains} : %v\n", links.Contains(uri))

	fmt.Printf("Test - {Contains invalid} : %v\n", links.Contains("invalid"))

	links.Remove(uri)
	fmt.Printf("Test - {Remove item} : %v\n", links)

	fmt.Printf("Test - {Is Empty} : %v\n", links.IsEmpty())

}

func _ExampleSyncList() {
	uri := "www.google.com/search"
	links := new(SyncList)

	links.Add(uri)
	fmt.Printf("Test - {Added} : %v\n", links)
	fmt.Printf("Test - {Contains} : %v\n", links.Contains(uri))
	fmt.Printf("Test - {Contains invalid} : %v\n", links.Contains("invalid"))

	links.Remove(uri)
	fmt.Printf("Test - {Remove item} : %v\n", links)

	
Output:

Test - {Added} : map[www.google.com/search:{}]
Test - {Is Empty} : false
Test - {Item} : {}
Test - {Contains} : true
Test - {Contains invalid} : false
Test - {Remove item} : map[]
Test - {Is Empty} : true

func (List) Add

func (l List) Add(item any)

func (List) Contains

func (l List) Contains(item any) bool

func (List) IsEmpty

func (l List) IsEmpty() bool

func (List) Remove

func (l List) Remove(item any)

type SyncList

type SyncList sync.Map

func (*SyncList) Add

func (l *SyncList) Add(item any)

func (*SyncList) Contains

func (l *SyncList) Contains(item any) bool

func (*SyncList) Remove

func (l *SyncList) Remove(item any)

type VariableLookup

type VariableLookup = func(name string) (value string, err error)

VariableLookup - type used in template.go

Jump to

Keyboard shortcuts

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