gotils

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: MIT Imports: 2 Imported by: 0

README

GOTILS

Golang Utilities

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyKind

func AnyKind(v Kinder, k ...reflect.Kind) bool

AnyKind returns true if v.Kind matchs k.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/acaosx/gotils"
)

func main() {
	v := reflect.ValueOf("gotils")
	fmt.Println(gotils.AnyKind(v, reflect.String))
	fmt.Println(gotils.AnyKind(v, reflect.Uint))
}
Output:

true
false

func StringFromBytes

func StringFromBytes(b []byte) string

StringFromBytes returns string from b without memory allocation.

Example
package main

import (
	"fmt"

	"github.com/acaosx/gotils"
)

func main() {
	fmt.Println(gotils.StringFromBytes([]byte{103, 111, 116, 105, 108, 115}))
}
Output:

gotils

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes returns bytes from s without memory allocation.

Example
package main

import (
	"fmt"

	"github.com/acaosx/gotils"
)

func main() {
	fmt.Println(gotils.StringToBytes("gotils"))
}
Output:

[103 111 116 105 108 115]

Types

type KindMap

type KindMap map[reflect.Kind]struct{}

KindMap map of reflect.Kind.

Example
package main

import (
	"fmt"
	"reflect"

	"github.com/acaosx/gotils"
)

func main() {
	v := gotils.NewKindMap(reflect.String, reflect.Int)
	fmt.Println(v.Has(reflect.String))
	fmt.Println(v.Has(reflect.Uint))
	fmt.Println(v.Has(reflect.Int))
}
Output:

true
false
true

func NewKindMap

func NewKindMap(k ...reflect.Kind) (m KindMap)

NewKindMap returns new KindMap of k.

func (KindMap) Has

func (m KindMap) Has(k reflect.Kind) bool

Has returns true if k is in m.

type Kinder

type Kinder interface {
	Kind() reflect.Kind
}

Kinder is an interface that warps Kind method.

Jump to

Keyboard shortcuts

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