utils

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToObj

func ByteToObj(buf []byte, out interface{}) (err error)

func CopySlice

func CopySlice[In any, Out any](in []In) []Out

CopySlice 进行slice的拷贝

func DeepCopySlice

func DeepCopySlice[In any](in []In) []In

DeepCopySlice 进行slice的拷贝

func MapToObj

func MapToObj(maps map[string]interface{}, out interface{}) error

func Marshal

func Marshal(in interface{}) (str string, err error)

func Max

func Max[T any](o1, o2 T) T

func Min

func Min[T any](o1, o2 T) T

func ObjToByte

func ObjToByte(in interface{}) (buf []byte, err error)

func ObjToJsonStr

func ObjToJsonStr(obj interface{}) (str string)

func ObjToMap

func ObjToMap(in interface{}) map[string]interface{}

func SliceMap

func SliceMap[In any, Out any](slice []In, f func(in In) Out) []Out

func SliceToMap

func SliceToMap[A any, ID comparable](slice []A, f func(element A) ID) maps.IMap[ID, A]

SliceToMap Slice to Map

example:

type Person struct {
	ID int
}
p1 := &Person{ID: 1}
p2 := &Person{ID: 2}
p3 := &Person{ID: 3}
people := make([]*Person, 0)
people = append(people, p1, p2, p3)
m := SliceToMap(people, func(element *Person) int {
	return element.ID
})
v, _ := m.Get(1)

func Unmarshal

func Unmarshal(in string, out interface{}) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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