utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTLSConfigForClient added in v0.3.0

func GenerateTLSConfigForClient() *tls.Config

func GenerateTLSConfigForServer added in v0.3.0

func GenerateTLSConfigForServer() *tls.Config

GenerateTLSConfigForServer 生成tls证书

func IsSameAddr added in v0.3.1

func IsSameAddr(addOne, addTwo net.Addr) bool

IsSameAddr 判断两个地址是否相同

func NewTLSConfigFromFile added in v0.3.0

func NewTLSConfigFromFile(tlsCertFile, tlsKeyFile string, insecureSkipVerifyForClient ...bool) (*tls.Config, error)

NewTLSConfigFromFile 通过证书文件生成证书信息

Types

type FakeAddr added in v0.3.0

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

FakeAddr 是一个虚地址对象,实现了net.Add

func NewFakeAddr added in v0.3.0

func NewFakeAddr(network, host, port string) *FakeAddr

NewFakeAddr 创建一个虚地址对象

func NewFakeAddr2 added in v0.3.0

func NewFakeAddr2(network, addr string) (*FakeAddr, error)

NewFakeAddr2 创建另一个不同参数的虚地址对象

func (*FakeAddr) Host added in v0.3.0

func (f *FakeAddr) Host() string

func (*FakeAddr) Network added in v0.3.0

func (f *FakeAddr) Network() string

func (*FakeAddr) Port added in v0.3.0

func (f *FakeAddr) Port() string

func (*FakeAddr) SetUdpAddr added in v0.3.0

func (f *FakeAddr) SetUdpAddr(udpAddr *net.UDPAddr)

func (*FakeAddr) String added in v0.3.0

func (f *FakeAddr) String() string

func (*FakeAddr) UdpAddr added in v0.3.0

func (f *FakeAddr) UdpAddr() *net.UDPAddr

type Map

type Map interface {
	// Load returns the value stored in the map for a key, or nil if no
	// value is present.
	// The ok result indicates whether value was found in the map.
	Load(key interface{}) (value interface{}, ok bool)
	// Store sets the value for a key.
	Store(key, value interface{})
	// LoadOrStore returns the existing value for the key if present.
	// Otherwise, it stores and returns the given value.
	// The loaded result is true if the value was loaded, false if stored.
	LoadOrStore(key, value interface{}) (actual interface{}, loaded bool)
	// Range calls f sequentially for each key and value present in the map.
	// If f returns false, range stops the iteration.
	Range(f func(key, value interface{}) bool)
	// Random returns a pair kv randomly.
	// If exist=false, no kv data is exist.
	Random() (key, value interface{}, exist bool)
	// Delete deletes the value for a key.
	Delete(key interface{})
	// Clear clears all current data in the map.
	Clear()
	// Len returns the length of the map.
	Len() int
}

Map is a concurrent map with loads, stores, and deletes. It is safe for multiple goroutines to call a Map's methods concurrently.

func AtomicMap

func AtomicMap() Map

AtomicMap creates a concurrent map with amortized-constant-time loads, stores, and deletes. It is safe for multiple goroutines to call a atomicMap's methods concurrently. From go v1.9 sync.Map.

func RwMap

func RwMap(capacity ...int) Map

RwMap creates a new concurrent safe map with sync.RWMutex. The normal Map is high-performance mapping under low concurrency conditions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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