bfe_util

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TimeZoneMap reference: https://en.wikipedia.org/wiki/List_of_military_time_zones
	TimeZoneMap = map[string]int{
		"Y": -12 * 3600,
		"X": -11 * 3600,
		"W": -10 * 3600,
		"V": -9 * 3600,
		"U": -8 * 3600,
		"T": -7 * 3600,
		"S": -6 * 3600,
		"R": -5 * 3600,
		"Q": -4 * 3600,
		"P": -3 * 3600,
		"O": -2 * 3600,
		"N": -1 * 3600,
		"Z": 0,
		"A": 1 * 3600,
		"B": 2 * 3600,
		"C": 3 * 3600,
		"D": 4 * 3600,
		"E": 5 * 3600,
		"F": 6 * 3600,
		"G": 7 * 3600,
		"H": 8 * 3600,
		"I": 9 * 3600,
		"K": 10 * 3600,
		"L": 11 * 3600,
		"M": 12 * 3600,
	}
)

Functions

func AbnormalExit

func AbnormalExit()

func BackupFile

func BackupFile(path string, bakPath string) error

BackupFile backup given file.

func CheckNilField

func CheckNilField(object interface{}, allowNoPointerField bool) error

CheckNilField check if a struct has a nil field if allowNoPointerField is false, it also check if fields are all pointers if param object is not a struct , return nil

func CheckStaticFile

func CheckStaticFile(filename string, sizeLimit int64) error

CheckStaticFile check local file

func ConfPathProc

func ConfPathProc(confPath string, confRoot string) string

ConfPathProc return path of config file

Params:

  • confPath: origin path for config file
  • confRoot: root path of ALL config

Returns:

the final path of config file
(1) path starts with "/", it's absolute path, return path untouched
(2) else, it's relative path, return path.Join(confRoot, path)

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile copy src file to dst file. return file length, error

func CopyWithoutBuffer

func CopyWithoutBuffer(wf bfe_http.WriteFlusher, src io.Reader) (written int64, err error)

CopyWithoutBuffer mimic the behavior of io.Copy.

func DumpJson

func DumpJson(jsonObject interface{}, filePath string, perm os.FileMode) error

DumpJson dumps json file.

func GetConnFile

func GetConnFile(conn net.Conn) (*os.File, error)

GetConnFile get a copy of underlying os.File of tcp conn

func GetTCPConn

func GetTCPConn(conn net.Conn) (*net.TCPConn, error)

GetTCPConn returns underlying TCPConn of given conn.

func GetVip

func GetVip(conn net.Conn) net.IP

GetVip return vip for given conn

func GetVipPort

func GetVipPort(conn net.Conn) (net.IP, int, error)

GetVipPort return vip and port for given conn

func GetsockoptMultiByte added in v1.6.0

func GetsockoptMultiByte(fd, level, opt int) ([]byte, error)

GetsockoptMultiByte returns the value of the socket option opt for the socket associated with fd at the given socket level.

func IsBigEndian

func IsBigEndian() bool

IsBigEndian check machine is big endian or not

func LoadJsonFile

func LoadJsonFile(path string, jsonObject interface{}) error

LoadJsonFile loads json content from file, unmarshal to jsonObject. check if all field is set if checkNilPointer is true check if any field is not pointer type if allowNoPointerField is false

func NativeUint16

func NativeUint16(data []byte) uint16

func ParseIpAndPort

func ParseIpAndPort(addr string) (net.IP, int, error)

ParseIpAndPort return parsed ip address

func ParseTime added in v1.2.0

func ParseTime(timeStr string) (time.Time, error)

ParseTime returns a time in UTC+0 time zone. Note: currently, we do not use time.LoadLocation func, because it has two issues: 1. abusing opening files: https://github.com/golang/go/issues/24844 2. the version of zone info file in all machines may differ.

func ParseTimeOfDay added in v1.2.0

func ParseTimeOfDay(timeStr string) (time.Time, int, error)

ParseTimeOfDay parser time string of a day timeStr: hhmmssZ, Z represents timezone return parsed time and offset of timezone

Types

type AddressFetcher

type AddressFetcher interface {
	// RemoteAddr returns the remote network address.
	RemoteAddr() net.Addr

	// LocalAddr returns the local network address.
	LocalAddr() net.Addr

	// VirtualAddr returns the virtual network address.
	VirtualAddr() net.Addr

	// BalancerAddr return the balancer network address. May be nil.
	BalancerAddr() net.Addr
}

AddressFetcher is the interface that group the address related method.

type CloseWriter

type CloseWriter interface {
	CloseWrite() error
}

CloseWriter is the interface that wraps the basic CloseWrite method.

type ConnFetcher

type ConnFetcher interface {
	// GetNetConn returns the underlying net.Conn
	GetNetConn() net.Conn
}

ConnFetcher is the interface that wrap the GetNetConn

type FixedPool

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

func NewFixedPool

func NewFixedPool(size int) *FixedPool

func (*FixedPool) GetBlock

func (p *FixedPool) GetBlock() []byte

GetBlock gets a byte slice from pool

func (*FixedPool) PutBlock

func (p *FixedPool) PutBlock(block []byte)

PutBlock releases a byte slice to pool

type MockConn

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

type MockHandler

type MockHandler func(conn net.Conn)

A MockHandler is an handler to process established conn on server side

type MockServer

type MockServer struct {
	Listener net.Listener

	// optional fields for tls server
	TLS    *tls.Config
	Config *http.Server

	// optional fields for tcp server
	Handler MockHandler
}

A MockServer is an tls/tcp server listening on a system-chosen port on the local loopback interface, for use in end-to-end tests.

func NewUnstartedServer

func NewUnstartedServer(handler interface{}) *MockServer

NewUnstartedServer returns a new Server but doesn't start it. After changing its configuration, the caller should call StartTLS. The caller should call Close when finished, to shut it down.

func (*MockServer) Close

func (s *MockServer) Close()

Close shuts down the server and blocks until all outstanding requests on this server have completed.

func (*MockServer) CloseClientConnections

func (s *MockServer) CloseClientConnections()

CloseClientConnections closes any currently open HTTP connections to the test Server.

func (*MockServer) Serve

func (s *MockServer) Serve(l net.Listener) error

func (*MockServer) StartTCP

func (s *MockServer) StartTCP()

StartTCP starts TCP on a server from NewUnstartedServer.

func (*MockServer) StartTLS

func (s *MockServer) StartTLS()

StartTLS starts TLS on a server from NewUnstartedServer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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