gommon

package module
v0.47.4 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	LowerTable   = `abcdefghijklmnopqrstuvwxyz`
	UpperTable   = `ABCDEFGHIJKLMNOPQRSTUVWXYZ`
	NumericTable = `0123456789`
	SymbolsTable = `!"#$%&'()*+,-./:;<=>?@[\]^_{|}~` + "`"
)

Variables

This section is empty.

Functions

func Compact added in v0.10.0

func Compact[T comparable](values []T) []T

Compact accepts a list and removes entries with empty values.

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Compact([]byte{0x00, 0x61, 0x62, 0x00, 0x63, 0x64, 0x00}))
}
Output:

[]byte{0x61, 0x62, 0x63, 0x64}
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]complex128{0, 1.9, 2.8, 3.7, 0.5})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex128, [(1.9+0i) (2.8+0i) (3.7+0i) (0.5+0i)]
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]complex64{0, 1.9, 2.8, 3.7, 0.5})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex64, [(1.9+0i) (2.8+0i) (3.7+0i) (0.5+0i)]
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]float32{0, 1.9, 2.8, 3.7, 0.5})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float32, [1.9 2.8 3.7 0.5]
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]float64{0, 1.9, 2.8, 3.7, 0.5})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float64, [1.9 2.8 3.7 0.5]
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]int{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int, [1 2 3 4]
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]int16{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int16, [1 2 3 4]
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]int32{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int32, [1 2 3 4]
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]int64{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int64, [1 2 3 4]
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]int8{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int8, [1 2 3 4]
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]rune{0x00, 0x61, 0x62, 0x00, 0x63, 0x64, 0x00})
	fmt.Printf("%T, %#x\n", v, v)
}
Output:

[]int32, [0x61 0x62 0x63 0x64]
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]string{"", "foo", "", "bar", ""})
	fmt.Printf("%T, %q\n", v, v)
}
Output:

[]string, ["foo" "bar"]
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uint{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint, [1 2 3 4]
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uint16{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint16, [1 2 3 4]
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uint32{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint32, [1 2 3 4]
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uint64{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint64, [1 2 3 4]
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uint8{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint8, [1 2 3 4]
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Compact([]uintptr{0, 1, 2, 0, 3, 4, 0})
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uintptr, [1 2 3 4]

func Copy added in v0.46.0

func Copy[T any](src T, dst *T)

Copy source into destination

func CopyValue added in v0.47.0

func CopyValue(src, dst reflect.Value) error

CopyValue source reflection object to destination reflection object

func Default

func Default[T any](v1, v2 T) T

Default takes two values. If the first value is not empty, it will be returned, else the second value will be returned.

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#x\n", gommon.Default(byte(0x79), byte(0x6e)))
	fmt.Printf("%#x\n", gommon.Default(byte(0x00), byte(0x6e)))
}
Output:

0x79
0x6e
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Default(complex128(1.9), complex128(2.8)))
	fmt.Printf("%#v\n", gommon.Default(complex128(0.0), complex128(2.8)))
}
Output:

(1.9+0i)
(2.8+0i)
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Default(complex64(1.9), complex64(2.8)))
	fmt.Printf("%#v\n", gommon.Default(complex64(0.0), complex64(2.8)))
}
Output:

(1.9+0i)
(2.8+0i)
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Default(float32(1.9), float32(2.8)))
	fmt.Printf("%#v\n", gommon.Default(float32(0.0), float32(2.8)))
}
Output:

1.9
2.8
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Default(1.9, 2.8))
	fmt.Printf("%#v\n", gommon.Default(0.0, 2.8))
}
Output:

1.9
2.8
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(1, 2))
	fmt.Printf("%v\n", gommon.Default(0, 2))
}
Output:

1
2
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(int16(1), int16(2)))
	fmt.Printf("%v\n", gommon.Default(int16(0), int16(2)))
}
Output:

1
2
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(int32(1), int32(2)))
	fmt.Printf("%v\n", gommon.Default(int32(0), int32(2)))
}
Output:

1
2
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(int64(1), int64(2)))
	fmt.Printf("%v\n", gommon.Default(int64(0), int64(2)))
}
Output:

1
2
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(int8(1), int8(2)))
	fmt.Printf("%v\n", gommon.Default(int8(0), int8(2)))
}
Output:

1
2
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#x\n", gommon.Default(rune(0x79), rune(0x6e)))
	fmt.Printf("%#x\n", gommon.Default(rune(0x00), rune(0x6e)))
}
Output:

0x79
0x6e
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%s\n", gommon.Default("value1", "value2"))
	fmt.Printf("%s\n", gommon.Default("", "value2"))
}
Output:

value1
value2
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uint(1), uint(2)))
	fmt.Printf("%v\n", gommon.Default(uint(0), uint(2)))
}
Output:

1
2
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uint16(1), uint16(2)))
	fmt.Printf("%v\n", gommon.Default(uint16(0), uint16(2)))
}
Output:

1
2
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uint32(1), uint32(2)))
	fmt.Printf("%v\n", gommon.Default(uint32(0), uint32(2)))
}
Output:

1
2
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uint64(1), uint64(2)))
	fmt.Printf("%v\n", gommon.Default(uint64(0), uint64(2)))
}
Output:

1
2
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uint8(1), uint8(2)))
	fmt.Printf("%v\n", gommon.Default(uint8(0), uint8(2)))
}
Output:

1
2
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Default(uintptr(1), uintptr(2)))
	fmt.Printf("%v\n", gommon.Default(uintptr(0), uintptr(2)))
}
Output:

1
2

func Empty

func Empty[T any](v T) bool

Empty check the value and return true if value is non-empty.

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(byte(0x00)))
	fmt.Println(gommon.Empty(byte(0x61)))
}
Output:

true
false
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(complex128(0.0)))
	fmt.Println(gommon.Empty(complex128(2.8)))
}
Output:

true
false
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(complex64(0.0)))
	fmt.Println(gommon.Empty(complex64(2.8)))
}
Output:

true
false
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(float32(0.0)))
	fmt.Println(gommon.Empty(float32(2.8)))
}
Output:

true
false
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(0.0))
	fmt.Println(gommon.Empty(2.8))
}
Output:

true
false
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(0))
	fmt.Println(gommon.Empty(1))
}
Output:

true
false
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(int16(0)))
	fmt.Println(gommon.Empty(int16(1)))
}
Output:

true
false
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(int32(0)))
	fmt.Println(gommon.Empty(int32(1)))
}
Output:

true
false
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(int64(0)))
	fmt.Println(gommon.Empty(int64(1)))
}
Output:

true
false
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(int8(0)))
	fmt.Println(gommon.Empty(int8(1)))
}
Output:

true
false
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(rune(0x00)))
	fmt.Println(gommon.Empty(rune(0x6e)))
}
Output:

true
false
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(""))
	fmt.Println(gommon.Empty("value"))
}
Output:

true
false
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uint(0)))
	fmt.Println(gommon.Empty(uint(1)))
}
Output:

true
false
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uint16(0)))
	fmt.Println(gommon.Empty(uint16(1)))
}
Output:

true
false
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uint32(0)))
	fmt.Println(gommon.Empty(uint32(1)))
}
Output:

true
false
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uint64(0)))
	fmt.Println(gommon.Empty(uint64(1)))
}
Output:

true
false
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uint8(0)))
	fmt.Println(gommon.Empty(uint8(1)))
}
Output:

true
false
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Empty(uintptr(0)))
	fmt.Println(gommon.Empty(uintptr(1)))
}
Output:

true
false

func First added in v0.32.0

func First[T any](slice []T) T

First item of slice returned

Example (String)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%s\n", gommon.First([]string{"one", "two"}))
}
Output:

one

func FuncMap added in v0.34.0

func FuncMap() map[string]any

FuncMap returns list of functions

func Has added in v0.10.0

func Has[T comparable](value T, values ...T) bool

Has test to see if a list has a particular element.

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(byte(0x62), byte(0x61), byte(0x62), byte(0x63), byte(0x64)))
	fmt.Println(gommon.Has(byte(0x65), byte(0x61), byte(0x62), byte(0x63), byte(0x64)))
}
Output:

true
false
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(complex128(2.8), complex128(1.9), complex128(2.8), complex128(3.7)))
	fmt.Println(gommon.Has(complex128(5), complex128(1.9), complex128(2.8), complex128(3.7)))
}
Output:

true
false
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(complex64(2.8), complex64(1.9), complex64(2.8), complex64(3.7)))
	fmt.Println(gommon.Has(complex64(5), complex64(1.9), complex64(2.8), complex64(3.7)))
}
Output:

true
false
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(float32(2.8), float32(1.9), float32(2.8), float32(3.7)))
	fmt.Println(gommon.Has(float32(5), float32(1.9), float32(2.8), float32(3.7)))
}
Output:

true
false
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(2.8, 1.9, 2.8, 3.7))
	fmt.Println(gommon.Has(float64(5), 1.9, 2.8, 3.7))
}
Output:

true
false
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(2, 1, 2, 3))
	fmt.Println(gommon.Has(5, 1, 2, 3))
}
Output:

true
false
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(int16(2), int16(1), int16(2), int16(3)))
	fmt.Println(gommon.Has(int16(5), int16(1), int16(2), int16(3)))
}
Output:

true
false
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(int32(2), int32(1), int32(2), int32(3)))
	fmt.Println(gommon.Has(int32(5), int32(1), int32(2), int32(3)))
}
Output:

true
false
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(int64(2), int64(1), int64(2), int64(3)))
	fmt.Println(gommon.Has(int64(5), int64(1), int64(2), int64(3)))
}
Output:

true
false
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(int8(2), int8(1), int8(2), int8(3)))
	fmt.Println(gommon.Has(int8(5), int8(1), int8(2), int8(3)))
}
Output:

true
false
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(rune(0x62), rune(0x61), rune(0x62), rune(0x63), rune(0x64)))
	fmt.Println(gommon.Has(rune(0x65), rune(0x61), rune(0x62), rune(0x63), rune(0x64)))
}
Output:

true
false
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has("value2", "value1", "value2", "value3"))
	fmt.Println(gommon.Has("value5", "value1", "value2", "value3"))
}
Output:

true
false
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uint(2), uint(1), uint(2), uint(3)))
	fmt.Println(gommon.Has(uint(5), uint(1), uint(2), uint(3)))
}
Output:

true
false
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uint16(2), uint16(1), uint16(2), uint16(3)))
	fmt.Println(gommon.Has(uint16(5), uint16(1), uint16(2), uint16(3)))
}
Output:

true
false
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uint32(2), uint32(1), uint32(2), uint32(3)))
	fmt.Println(gommon.Has(uint32(5), uint32(1), uint32(2), uint32(3)))
}
Output:

true
false
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uint64(2), uint64(1), uint64(2), uint64(3)))
	fmt.Println(gommon.Has(uint64(5), uint64(1), uint64(2), uint64(3)))
}
Output:

true
false
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uint8(2), uint8(1), uint8(2), uint8(3)))
	fmt.Println(gommon.Has(uint8(5), uint8(1), uint8(2), uint8(3)))
}
Output:

true
false
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Has(uintptr(2), uintptr(1), uintptr(2), uintptr(3)))
	fmt.Println(gommon.Has(uintptr(5), uintptr(1), uintptr(2), uintptr(3)))
}
Output:

true
false

func MustParse added in v0.21.0

func MustParse[T any](value string) T

MustParse return parsed value, or if error reflect.Zero value.

Example (Base64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(string(gommon.MustParse[gommon.Base64]("SGVsbG8")))
	fmt.Println(string(gommon.MustParse[gommon.Base64]("SGVsbG8=")))
}
Output:


Hello
Example (Bool)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[bool]("error"))
	fmt.Println(gommon.MustParse[bool]("true"))
	fmt.Println(gommon.MustParse[bool]("false"))
}
Output:

false
true
false
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[complex128]("error"))
	fmt.Println(gommon.MustParse[complex128]("123.987"))
	fmt.Println(gommon.MustParse[complex128]("-987.123"))
}
Output:

(0+0i)
(123.987+0i)
(-987.123+0i)
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[complex64]("error"))
	fmt.Println(gommon.MustParse[complex64]("123.987"))
	fmt.Println(gommon.MustParse[complex64]("-987.123"))
}
Output:

(0+0i)
(123.987+0i)
(-987.123+0i)
Example (Dsn)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[gommon.DSN]("invalid:/unknown"))
	fmt.Println(gommon.MustParse[gommon.DSN]("https://user:pass@tcp(domain.tld:1234)/path?key=value"))
}
Output:


https://user:pass@tcp(domain.tld:1234)/path?key=value
Example (Duration)
package main

import (
	"fmt"
	"time"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[time.Duration]("error"))
	fmt.Println(gommon.MustParse[time.Duration]("5m45s"))
}
Output:

0s
5m45s
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[float32]("error"))
	fmt.Println(gommon.MustParse[float32]("123.987"))
	fmt.Println(gommon.MustParse[float32]("-987.123"))
}
Output:

0
123.987
-987.123
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[float64]("error"))
	fmt.Println(gommon.MustParse[float64]("123.987"))
	fmt.Println(gommon.MustParse[float64]("-987.123"))
}
Output:

0
123.987
-987.123
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[int]("error"))
	fmt.Println(gommon.MustParse[int]("123"))
	fmt.Println(gommon.MustParse[int]("-128"))
}
Output:

0
123
-128
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[int16]("error"))
	fmt.Println(gommon.MustParse[int16]("123"))
	fmt.Println(gommon.MustParse[int16]("-128"))
}
Output:

0
123
-128
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[int32]("error"))
	fmt.Println(gommon.MustParse[int32]("123"))
	fmt.Println(gommon.MustParse[int32]("-128"))
}
Output:

0
123
-128
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[int64]("error"))
	fmt.Println(gommon.MustParse[int64]("123"))
	fmt.Println(gommon.MustParse[int64]("-128"))
}
Output:

0
123
-128
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[int8]("error"))
	fmt.Println(gommon.MustParse[int8]("123"))
	fmt.Println(gommon.MustParse[int8]("-128"))
}
Output:

0
123
-128
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[string]("ok"))
}
Output:

ok
Example (Time)
package main

import (
	"fmt"
	"time"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[time.Time]("error").UTC())
	fmt.Println(gommon.MustParse[time.Time]("2006-01-02T15:04:05Z").UTC())
}
Output:

0001-01-01 00:00:00 +0000 UTC
2006-01-02 15:04:05 +0000 UTC
Example (Timestamp)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[gommon.Timestamp]("error").Time().UTC())
	fmt.Println(gommon.MustParse[gommon.Timestamp]("1136214245").Time().UTC())
}
Output:

1970-01-01 00:00:00 +0000 UTC
2006-01-02 15:04:05 +0000 UTC
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uint]("error"))
	fmt.Println(gommon.MustParse[uint]("123"))
}
Output:

0
123
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uint16]("error"))
	fmt.Println(gommon.MustParse[uint16]("123"))
}
Output:

0
123
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uint32]("error"))
	fmt.Println(gommon.MustParse[uint32]("123"))
}
Output:

0
123
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uint64]("error"))
	fmt.Println(gommon.MustParse[uint64]("123"))
}
Output:

0
123
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uint8]("error"))
	fmt.Println(gommon.MustParse[uint8]("123"))
}
Output:

0
123
Example (Uintptr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[uintptr]("error"))
	fmt.Println(gommon.MustParse[uintptr]("1a"))
}
Output:

0
26
Example (Url)
package main

import (
	"fmt"
	"net/url"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[*url.URL]("://user:abc"))
	fmt.Println(gommon.MustParse[*url.URL]("http://example.domain.tld:8080/path?query=value"))
}
Output:

<nil>
http://example.domain.tld:8080/path?query=value
Example (UrlValues)
package main

import (
	"fmt"
	"net/url"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.MustParse[url.Values]("key;value"))
	fmt.Println(gommon.MustParse[url.Values]("key=value"))
}
Output:

map[]
map[key:[value]]

func NewCopy added in v0.47.0

func NewCopy[T any](v T) T

NewCopy create and copy a new object

func Parse added in v0.16.0

func Parse[T any](value string) (T, error)

Parse string value to standard or underlying type.

Example (Bool)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[bool]("error"))
	fmt.Println(gommon.Parse[bool]("true"))
	fmt.Println(gommon.Parse[bool]("false"))
}
Output:

false strconv.ParseBool: parsing "error": invalid syntax
true <nil>
false <nil>
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[complex128]("error"))
	fmt.Println(gommon.Parse[complex128]("123.987"))
	fmt.Println(gommon.Parse[complex128]("-987.123"))
}
Output:

(0+0i) strconv.ParseComplex: parsing "error": invalid syntax
(123.987+0i) <nil>
(-987.123+0i) <nil>
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[complex64]("error"))
	fmt.Println(gommon.Parse[complex64]("123.987"))
	fmt.Println(gommon.Parse[complex64]("-987.123"))
}
Output:

(0+0i) strconv.ParseComplex: parsing "error": invalid syntax
(123.987+0i) <nil>
(-987.123+0i) <nil>
Example (Duration)
package main

import (
	"fmt"
	"time"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[time.Duration]("error"))
	fmt.Println(gommon.Parse[time.Duration]("5m45s"))
}
Output:

0s time: invalid duration "error"
5m45s <nil>
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[float32]("error"))
	fmt.Println(gommon.Parse[float32]("123.987"))
	fmt.Println(gommon.Parse[float32]("-987.123"))
}
Output:

0 strconv.ParseFloat: parsing "error": invalid syntax
123.987 <nil>
-987.123 <nil>
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[float64]("error"))
	fmt.Println(gommon.Parse[float64]("123.987"))
	fmt.Println(gommon.Parse[float64]("-987.123"))
}
Output:

0 strconv.ParseFloat: parsing "error": invalid syntax
123.987 <nil>
-987.123 <nil>
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[int]("error"))
	fmt.Println(gommon.Parse[int]("123"))
	fmt.Println(gommon.Parse[int]("-128"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
123 <nil>
-128 <nil>
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[int16]("error"))
	fmt.Println(gommon.Parse[int16]("123"))
	fmt.Println(gommon.Parse[int16]("-128"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
123 <nil>
-128 <nil>
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[int32]("error"))
	fmt.Println(gommon.Parse[int32]("123"))
	fmt.Println(gommon.Parse[int32]("-128"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
123 <nil>
-128 <nil>
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[int64]("error"))
	fmt.Println(gommon.Parse[int64]("123"))
	fmt.Println(gommon.Parse[int64]("-128"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
123 <nil>
-128 <nil>
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[int8]("error"))
	fmt.Println(gommon.Parse[int8]("123"))
	fmt.Println(gommon.Parse[int8]("-128"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
123 <nil>
-128 <nil>
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[string]("ok"))
}
Output:

ok <nil>
Example (Time)
package main

import (
	"fmt"
	"time"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[time.Time]("error"))
	fmt.Println(gommon.Parse[time.Time]("2006-01-02T15:04:05Z"))
}
Output:

0001-01-01 00:00:00 +0000 UTC parsing time "error" as "2006-01-02T15:04:05Z07:00": cannot parse "error" as "2006"
2006-01-02 15:04:05 +0000 UTC <nil>
Example (Timestamp)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[gommon.Timestamp]("error"))
	fmt.Println(gommon.Parse[gommon.Timestamp]("1136214245"))
}
Output:

0 strconv.ParseInt: parsing "error": invalid syntax
1136214245 <nil>
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uint]("error"))
	fmt.Println(gommon.Parse[uint]("123"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
123 <nil>
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uint16]("error"))
	fmt.Println(gommon.Parse[uint16]("123"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
123 <nil>
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uint32]("error"))
	fmt.Println(gommon.Parse[uint32]("123"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
123 <nil>
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uint64]("error"))
	fmt.Println(gommon.Parse[uint64]("123"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
123 <nil>
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uint8]("error"))
	fmt.Println(gommon.Parse[uint8]("123"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
123 <nil>
Example (Uintptr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Println(gommon.Parse[uintptr]("error"))
	fmt.Println(gommon.Parse[uintptr]("1a"))
}
Output:

0 strconv.ParseUint: parsing "error": invalid syntax
26 <nil>

func ParseBool added in v0.16.0

func ParseBool(str string) (bool, error)

ParseBool returns the boolean value represented by the string. It accepts 1, t, T, TRUE, true, True, On, on, 0, f, F, FALSE, false, False, Off, off. Any other value returns an error.

func PathEmpty added in v0.38.0

func PathEmpty(path string) bool

func PathExist added in v0.38.0

func PathExist(path string) bool

func Ptr

func Ptr[T comparable](v T) *T

Ptr return pointer of the value.

Example (Bool)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(true)
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*bool = true
Example (Byte)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(byte(0x61))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint8 = 97
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(complex128(123.987))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*complex128 = (123.987+0i)
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(complex64(123.987))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*complex64 = (123.987+0i)
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(float32(123.987))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*float32 = 123.987
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(float64(123.987))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*float64 = 123.987
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(int(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int = 123
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(int16(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int16 = 123
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(int32(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int32 = 123
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(int64(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int64 = 123
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(int8(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int8 = 123
Example (Rune)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(rune(0x61))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*int32 = 97
Example (String)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr("value")
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*string = value
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uint(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint = 123
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uint16(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint16 = 123
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uint32(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint32 = 123
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uint64(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint64 = 123
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uint8(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uint8 = 123
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ptr := gommon.Ptr(uintptr(123))
	fmt.Printf("%T = %v\n", ptr, *ptr)
}
Output:

*uintptr = 123

func Random added in v0.24.0

func Random(generator RandomGenerator, length int) string

func SemverCompare added in v0.37.0

func SemverCompare(constraint, version string) (bool, error)

func Signal added in v0.28.1

func Signal(sigs ...os.Signal) <-chan os.Signal

Signal is channel of system signal

func Split added in v0.16.0

func Split[T comparable](value, sep string) []T

Split a string into a list of type.

Example (Bool)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[bool]("true,,false", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]bool, [true false]
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[complex128]("123.987,0,-987.123", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex128, [(123.987+0i) (0+0i) (-987.123+0i)]
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[complex64]("123.987,0,-987.123", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex64, [(123.987+0i) (0+0i) (-987.123+0i)]
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[float32]("123.987,0,-987.123", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float32, [123.987 0 -987.123]
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[float64]("123.987,0,-987.123", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float64, [123.987 0 -987.123]
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[int]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int, [1 0 2]
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[int16]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int16, [1 0 2]
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[int32]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int32, [1 0 2]
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[int64]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int64, [1 0 2]
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[int8]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int8, [1 0 2]
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[string]("value1,value2,value3", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]string, [value1 value2 value3]
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[uint]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint, [1 0 2]
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[uint16]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint16, [1 0 2]
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[uint32]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint32, [1 0 2]
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[uint64]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint64, [1 0 2]
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.Split[uint8]("1,0,2", ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint8, [1 0 2]

func SplitSlice added in v0.25.0

func SplitSlice[T comparable](values []string, sep string) []T

SplitSlice a strings into a list of type.

Example (Bool)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[bool]([]string{"true,", "false"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]bool, [true false]
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[complex128]([]string{"123.987,0", "-987.123"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex128, [(123.987+0i) (0+0i) (-987.123+0i)]
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[complex64]([]string{"123.987,0", "-987.123"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]complex64, [(123.987+0i) (0+0i) (-987.123+0i)]
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[float32]([]string{"123.987,0,-987.123"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float32, [123.987 0 -987.123]
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[float64]([]string{"123.987,0,-987.123"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]float64, [123.987 0 -987.123]
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[int]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int, [1 0 2]
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[int16]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int16, [1 0 2]
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[int32]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int32, [1 0 2]
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[int64]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int64, [1 0 2]
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[int8]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]int8, [1 0 2]
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[string]([]string{"value1,value2", "value3"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]string, [value1 value2 value3]
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[uint]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint, [1 0 2]
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[uint16]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint16, [1 0 2]
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[uint32]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint32, [1 0 2]
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[uint64]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint64, [1 0 2]
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	v := gommon.SplitSlice[uint8]([]string{"1,0", "2"}, ",")
	fmt.Printf("%T, %v\n", v, v)
}
Output:

[]uint8, [1 0 2]

func Subst added in v0.34.0

func Subst(input []byte) ([]byte, error)

func SubstIO added in v0.36.0

func SubstIO(input io.Reader, output io.Writer) error

func Sum added in v0.44.0

func Sum(hashName string, data []byte) (string, error)

func SumFn added in v0.44.0

func SumFn(h hash.Hash, data []byte) string

func Ternary

func Ternary[T any](v bool, vTrue, vFalse T) T

Ternary takes a test boolean value, and two any values. If the test is true, the first value will be returned. If the test is empty, the second value will be returned.

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#x\n", gommon.Ternary(true, byte(0x79), byte(0x6e)))
	fmt.Printf("%#x\n", gommon.Ternary(false, byte(0x79), byte(0x6e)))
}
Output:

0x79
0x6e
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Ternary(true, complex128(1.9), complex128(2.8)))
	fmt.Printf("%#v\n", gommon.Ternary(false, complex128(1.9), complex128(2.8)))
}
Output:

(1.9+0i)
(2.8+0i)
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Ternary(true, complex64(1.9), complex64(2.8)))
	fmt.Printf("%#v\n", gommon.Ternary(false, complex64(1.9), complex64(2.8)))
}
Output:

(1.9+0i)
(2.8+0i)
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Ternary(true, float32(1.9), float32(2.8)))
	fmt.Printf("%#v\n", gommon.Ternary(false, float32(1.9), float32(2.8)))
}
Output:

1.9
2.8
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Ternary(true, 1.9, 2.8))
	fmt.Printf("%#v\n", gommon.Ternary(false, 1.9, 2.8))
}
Output:

1.9
2.8
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, 1, 2))
	fmt.Printf("%v\n", gommon.Ternary(false, 1, 2))
}
Output:

1
2
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, int16(1), int16(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, int16(1), int16(2)))
}
Output:

1
2
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, int32(1), int32(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, int32(1), int32(2)))
}
Output:

1
2
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, int64(1), int64(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, int64(1), int64(2)))
}
Output:

1
2
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, int8(1), int8(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, int8(1), int8(2)))
}
Output:

1
2
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#x\n", gommon.Ternary(true, rune(0x79), rune(0x6e)))
	fmt.Printf("%#x\n", gommon.Ternary(false, rune(0x79), rune(0x6e)))
}
Output:

0x79
0x6e
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%s\n", gommon.Ternary(true, "True", "False"))
	fmt.Printf("%s\n", gommon.Ternary(false, "True", "False"))
}
Output:

True
False
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uint(1), uint(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uint(1), uint(2)))
}
Output:

1
2
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uint16(1), uint16(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uint16(1), uint16(2)))
}
Output:

1
2
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uint32(1), uint32(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uint32(1), uint32(2)))
}
Output:

1
2
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uint64(1), uint64(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uint64(1), uint64(2)))
}
Output:

1
2
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uint8(1), uint8(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uint8(1), uint8(2)))
}
Output:

1
2
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Ternary(true, uintptr(1), uintptr(2)))
	fmt.Printf("%v\n", gommon.Ternary(false, uintptr(1), uintptr(2)))
}
Output:

1
2

func UnPtr added in v0.41.0

func UnPtr[T any](v *T) T

func Uniq added in v0.20.0

func Uniq[T comparable](v []T) []T

Uniq remove duplicate entries

Example (Bytes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#v\n", gommon.Uniq([]byte{0x61, 0x62, 0x61, 0x63}))
}
Output:

[]byte{0x61, 0x62, 0x63}
Example (Complex128)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]complex128{1.9, 2.8, 1.9, 3.7}))
}
Output:

[(1.9+0i) (2.8+0i) (3.7+0i)]
Example (Complex64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]complex64{1.9, 2.8, 1.9, 3.7}))
}
Output:

[(1.9+0i) (2.8+0i) (3.7+0i)]
Example (Float32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]float32{1.9, 2.8, 1.9, 3.7}))
}
Output:

[1.9 2.8 3.7]
Example (Float64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]float64{1.9, 2.8, 1.9, 3.7}))
}
Output:

[1.9 2.8 3.7]
Example (Int)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]int{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Int16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]int16{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Int32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]int32{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Int64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]int64{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Int8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]int8{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Runes)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%#x\n", gommon.Uniq([]rune{0x61, 0x62, 0x61, 0x63}))
}
Output:

[0x61 0x62 0x63]
Example (Strings)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]string{"v1", "v2", "v1", "v3"}))
}
Output:

[v1 v2 v3]
Example (Uint)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uint{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Uint16)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uint16{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Uint32)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uint32{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Uint64)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uint64{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (Uint8)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uint8{1, 2, 1, 3}))
}
Output:

[1 2 3]
Example (UintPtr)
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	fmt.Printf("%v\n", gommon.Uniq([]uintptr{1, 2, 1, 3}))
}
Output:

[1 2 3]

func WrapParse added in v0.38.0

func WrapParse[T any](value string) (any, error)

WrapParse return any instead of type

func Zero added in v0.32.0

func Zero[T any]() T

Zero return empty item of type

Types

type Base64 added in v0.23.0

type Base64 []byte

Base64 standard type

func ParseBase64 added in v0.23.0

func ParseBase64(str string) (Base64, error)

ParseBase64 decode to Base64.

func (Base64) Encode added in v0.38.0

func (v Base64) Encode() string

Encode return Base64 encoded

func (Base64) MarshalJSON added in v0.23.0

func (v Base64) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Base64) MarshalText added in v0.23.0

func (v Base64) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Base64) MarshalYAML added in v0.23.0

func (v Base64) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (Base64) String added in v0.37.0

func (v Base64) String() string

String implements the fmt.Stringer interface.

func (*Base64) UnmarshalENV added in v0.23.0

func (v *Base64) UnmarshalENV(data []byte) error

UnmarshalENV implements the env.Unmarshaler interface.

func (*Base64) UnmarshalJSON added in v0.23.0

func (v *Base64) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Base64) UnmarshalText added in v0.23.0

func (v *Base64) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Base64) UnmarshalYAML added in v0.23.0

func (v *Base64) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Complex added in v0.43.0

type Complex interface {
	~complex64 | ~complex128
}

Complex generic type for complex64 and complex128

type Converter added in v0.43.0

type Converter interface {
	Interface() any
	ToString() Value[string]
	ToBool() Value[bool]
	ToInt() Value[int]
	ToInt8() Value[int8]
	ToInt16() Value[int16]
	ToInt32() Value[int32]
	ToInt64() Value[int64]
	ToUint() Value[uint]
	ToUint8() Value[uint8]
	ToUint16() Value[uint16]
	ToUint32() Value[uint32]
	ToUint64() Value[uint64]
	ToUintPtr() Value[uintptr]
	ToFloat32() Value[float32]
	ToFloat64() Value[float64]
	ToComplex64() Value[complex64]
	ToComplex128() Value[complex128]
}

Converter interface for Convert

func Convert added in v0.43.0

func Convert(v any) Converter

Convert value to comparable types

type DSN added in v0.14.0

type DSN struct {
	Scheme   string
	Username string
	Password string
	Protocol string
	Endpoint string
	Port     int
	Path     string
	Queries  url.Values
}

DSN (Data Source Name) is advanced structure for describe to connection a data source.

func ParseDSN added in v0.26.0

func ParseDSN(str string) (DSN, error)

ParseDSN parses a raw dsn into a DSN structure.

func (DSN) MarshalJSON added in v0.14.0

func (v DSN) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (DSN) MarshalText added in v0.14.0

func (v DSN) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (DSN) MarshalYAML added in v0.14.0

func (v DSN) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (DSN) Redacted added in v0.33.0

func (v DSN) Redacted() string

Redacted is like String but replaces any password with "xxxxx".

func (DSN) String added in v0.14.0

func (v DSN) String() string

String reassembles the DSN into a valid DSN string.

func (*DSN) UnmarshalENV added in v0.20.0

func (v *DSN) UnmarshalENV(data []byte) error

UnmarshalENV implements the env.Unmarshaler interface.

func (*DSN) UnmarshalJSON added in v0.14.0

func (v *DSN) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*DSN) UnmarshalText added in v0.14.0

func (v *DSN) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*DSN) UnmarshalYAML added in v0.14.0

func (v *DSN) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Float added in v0.43.0

type Float interface {
	~float32 | ~float64
}

Float generic type for float32 and float64

type Number added in v0.43.0

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

Number generic type for int, int8, int16, int32, int64, uint, uint8, uint16, uint32 and uint64

type RandomGenerator added in v0.38.0

type RandomGenerator interface {
	Generate(length int) string
}

func NewAlphanumericRandom added in v0.38.0

func NewAlphanumericRandom() RandomGenerator

func NewCustomRandom added in v0.38.0

func NewCustomRandom(chars string) RandomGenerator

func NewLettersRandom added in v0.38.0

func NewLettersRandom() RandomGenerator

func NewLowerLettersRandom added in v0.38.0

func NewLowerLettersRandom() RandomGenerator

func NewNumberRandom added in v0.38.0

func NewNumberRandom() RandomGenerator

func NewStandardRandom added in v0.38.0

func NewStandardRandom() RandomGenerator

func NewUpperLettersRandom added in v0.38.0

func NewUpperLettersRandom() RandomGenerator

type StringSlice added in v0.18.0

type StringSlice []string

StringSlice implement Marshaler and Unmarshaler interfaces.

func (StringSlice) MarshalJSON added in v0.18.0

func (v StringSlice) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (StringSlice) MarshalText added in v0.18.0

func (v StringSlice) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (StringSlice) MarshalYAML added in v0.18.0

func (v StringSlice) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*StringSlice) UnmarshalJSON added in v0.18.0

func (v *StringSlice) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*StringSlice) UnmarshalText added in v0.18.0

func (v *StringSlice) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*StringSlice) UnmarshalYAML added in v0.18.0

func (v *StringSlice) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type StructMapDecoder added in v0.45.0

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

func NewStructMapDecoder added in v0.45.0

func NewStructMapDecoder(in map[string]any) *StructMapDecoder

func (*StructMapDecoder) Decode added in v0.45.0

func (dec *StructMapDecoder) Decode(out any) error

func (*StructMapDecoder) SetTag added in v0.45.0

func (dec *StructMapDecoder) SetTag(tag string) *StructMapDecoder

type StructMapEncoder added in v0.45.0

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

func NewStructMapEncoder added in v0.45.0

func NewStructMapEncoder(in any) *StructMapEncoder

func (*StructMapEncoder) Encode added in v0.45.0

func (enc *StructMapEncoder) Encode(out map[string]any) error

func (*StructMapEncoder) SetTag added in v0.45.0

func (enc *StructMapEncoder) SetTag(tag string) *StructMapEncoder

type Substitution added in v0.37.0

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

func NewSubstitution added in v0.37.0

func NewSubstitution(input io.Reader) *Substitution

func (*Substitution) Execute added in v0.37.0

func (s *Substitution) Execute(output io.Writer) error

func (*Substitution) Func added in v0.37.0

func (s *Substitution) Func(name string, fn any) *Substitution

func (*Substitution) Funcs added in v0.37.0

func (s *Substitution) Funcs(funcMap map[string]any) *Substitution

type Timestamp added in v0.11.0

type Timestamp int64

Timestamp is alias of time.Time with Marshaler and Unmarshaler interfaces.

func ParseTimestamp added in v0.22.0

func ParseTimestamp(value string) (Timestamp, error)

ParseTimestamp decode to Timestamp.

Example
package main

import (
	"fmt"

	"gitlab.com/evolves-fr/gommon"
)

func main() {
	ts, err := gommon.ParseTimestamp("1136214245")
	if err != nil {
		panic(err)
	}

	fmt.Println(ts.Time().UTC().String())
}
Output:

2006-01-02 15:04:05 +0000 UTC

func (Timestamp) MarshalBinary added in v0.12.0

func (t Timestamp) MarshalBinary() ([]byte, error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (Timestamp) MarshalJSON added in v0.11.0

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (Timestamp) MarshalText added in v0.12.0

func (t Timestamp) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (Timestamp) MarshalYAML added in v0.11.0

func (t Timestamp) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (Timestamp) String added in v0.38.0

func (t Timestamp) String() string

String implements the fmt.Stringer interface.

func (Timestamp) Time added in v0.11.0

func (t Timestamp) Time() time.Time

Time return standard time.Time object.

func (*Timestamp) UnmarshalBinary added in v0.12.0

func (t *Timestamp) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

func (*Timestamp) UnmarshalENV added in v0.22.0

func (t *Timestamp) UnmarshalENV(data []byte) error

UnmarshalENV implements the env.Unmarshaler interface.

func (*Timestamp) UnmarshalJSON added in v0.11.0

func (t *Timestamp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Timestamp) UnmarshalText added in v0.12.0

func (t *Timestamp) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (*Timestamp) UnmarshalYAML added in v0.11.0

func (t *Timestamp) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type Value added in v0.43.0

type Value[T comparable] struct {
	Value T
	Valid bool
}

Directories

Path Synopsis
http

Jump to

Keyboard shortcuts

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