util

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidSessionType invalid session type
	ErrInvalidSessionType = fmt.Errorf("invalid session type")
	// ErrInvalidSessionIDLength invalid session id length
	ErrInvalidSessionIDLength = fmt.Errorf("invalid session id length")
)

Functions

func GUID

func GUID() string

func HashString

func HashString(str string) string

func IsGroupUID added in v0.0.5

func IsGroupUID(uid string) bool

func Min

func Min[T Integer](a, b T) T

func ParseSession added in v0.0.7

func ParseSession(s string) (tp messagev1.SessionType, from, to types.ID, err error)

func RandIntn

func RandIntn(n int) int

RandIntn returns a random number in [0, n).

func Session added in v0.0.7

func Session(tp messagev1.SessionType, from, to types.ID) string

Session generate session id

switch tpye {
case messagev1.SessionType_SingleChat:
	001fromUIDtoUID
case messagev1.SessionType_GroupChat:
	010groupID00000000
}

func Sha256

func Sha256(data []byte) []byte

func UUID

func UUID() string

UUID returns a short version of UUID v4.

Types

type Integer added in v0.0.5

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

type Set added in v0.0.5

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

func NewSet added in v0.0.5

func NewSet[T comparable]() *Set[T]

func (*Set[T]) Add added in v0.0.5

func (s *Set[T]) Add(elem ...T)

func (*Set[T]) Contains added in v0.0.5

func (s *Set[T]) Contains(elem T) bool

func (*Set[T]) Remove added in v0.0.5

func (s *Set[T]) Remove(elem ...T)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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