utils

package
v0.0.0-...-30a31b1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRequestTimeout for request timeout error
	ErrRequestTimeout = errors.New("request timeout")
	ErrMQEmpty        = errors.New("MessageQueue is nil")
	ErrOffset         = errors.New("offset < 0")
	ErrNumbers        = errors.New("numbers < 0")
)
View Source
var (
	LocalIP string
)

Functions

func AbsInt

func AbsInt(i int) int

func CheckError

func CheckError(action string, err error)

func ClientIP4

func ClientIP4() ([]byte, error)

func FakeIP

func FakeIP() []byte

func FileReadAll

func FileReadAll(path string) ([]byte, error)

func GetAddressByBytes

func GetAddressByBytes(data []byte) string

func HashString

func HashString(s string) int

HashString hashes a string to a unique hashcode.

func MakeFileIfNotExist

func MakeFileIfNotExist(path string) error

func MinInt

func MinInt(a, b int) int

func StrJoin

func StrJoin(str, key string, value interface{}) string

func UnCompress

func UnCompress(data []byte) []byte

func WriteToFile

func WriteToFile(path string, data []byte) error

Types

type RingNodesBuffer

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

1.需要能够动态扩容 2.缩容看情况 3.read的时候需要block 4.线程安全

func NewRingNodesBuffer

func NewRingNodesBuffer(cap uint64) *RingNodesBuffer

func (*RingNodesBuffer) Cap

func (rb *RingNodesBuffer) Cap() uint64

Cap returns the capacity of this ring buffer.

func (*RingNodesBuffer) Destroy

func (r *RingNodesBuffer) Destroy()

func (*RingNodesBuffer) Read

func (r *RingNodesBuffer) Read(timeout time.Duration) (data []byte, err error)

直接返回数据

func (*RingNodesBuffer) ReadBySize

func (r *RingNodesBuffer) ReadBySize(data []byte, timeout time.Duration) (n int, err error)

知道大小,传进去解析

func (*RingNodesBuffer) Size

func (r *RingNodesBuffer) Size() uint64

func (*RingNodesBuffer) Write

func (r *RingNodesBuffer) Write(b []byte) error

type Set

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

func NewSet

func NewSet() Set

func (*Set) Add

func (s *Set) Add(v UniqueItem)

func (*Set) AddKV

func (s *Set) AddKV(k, v string)

func (*Set) Contains

func (s *Set) Contains(k string) (UniqueItem, bool)

func (*Set) Len

func (s *Set) Len() int

func (*Set) MarshalJSON

func (s *Set) MarshalJSON() ([]byte, error)

func (Set) UnmarshalJSON

func (s Set) UnmarshalJSON(data []byte) (err error)

type StringUnique

type StringUnique string

func (StringUnique) UniqueID

func (str StringUnique) UniqueID() string

type UniqueItem

type UniqueItem interface {
	UniqueID() string
}

Jump to

Keyboard shortcuts

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