helper

package
v0.0.0-...-988eabb Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BYTE     = 1.0
	KILOBYTE = 1024 * BYTE
	MEGABYTE = 1024 * KILOBYTE
	GIGABYTE = 1024 * MEGABYTE
	TERABYTE = 1024 * GIGABYTE
)

copy from https://github.com/cloudfoundry/bytefmt/blob/master/bytes.go

Variables

View Source
var ErrConnReset = errors.New("Conn reset")
View Source
var ErrNoSNI = errors.New("No SNI in protocol")
View Source
var ErrPKIStoreNotInit = errors.New("PKI store is not inited")
View Source
var ErrReadTimeout = errors.New("read timeout")
View Source
var ErrTLSClientHello = errors.New("Invalid tls client hello")
View Source
var ErrTLSIncomplete = errors.New("TLS header incomplete")
View Source
var ErrWriteTimeout = errors.New("write timeout")

Functions

func AsyncNotify

func AsyncNotify(ch chan struct{})

asyncNotify is used to signal a waiting goroutine

func AsyncSendErr

func AsyncSendErr(ch chan error, err error)

func ByteSize

func ByteSize(bytes uint64) string

ByteSize returns a human-readable byte string of the form 10M, 12.5K, and so forth. The following units are available:

T: Terabyte
G: Gigabyte
M: Megabyte
K: Kilobyte
B: Byte

The unit that results in the smallest number greater than or equal to 1 is always chosen.

func CreateRootCA

func CreateRootCA(dir string) error

func GenerateTLSConfig

func GenerateTLSConfig() *tls.Config

Setup a bare-bones TLS config for the server

func GetLocalIPSet

func GetLocalIPSet() map[string]bool

func GetLocalIPv4

func GetLocalIPv4() []string

func GetRequestURLString

func GetRequestURLString(req *http.Request) string

func HTTPProxyConnect

func HTTPProxyConnect(proxyURL *url.URL, c net.Conn, addr string) error

func IPv42Int

func IPv42Int(ip string) (int64, error)

func IsConnClosed

func IsConnClosed(c net.Conn) error

func IsPrivateIP

func IsPrivateIP(ip string) bool

func IsTimeoutError

func IsTimeoutError(err error) bool

func Long2IPv4

func Long2IPv4(i uint64) string

func PKCS7Pad

func PKCS7Pad(buf *bytes.Buffer, blen int)

func PKCS7Unpad

func PKCS7Unpad(in []byte) []byte

Returns slice of the original data without padding.

func PeekTLSServerName

func PeekTLSServerName(reader PeekReader) (string, error)

func PrepareRegexp

func PrepareRegexp(rule string) (*regexp.Regexp, error)

func ProxyDial

func ProxyDial(proxyURL string, laddr, raddr string, timeout time.Duration, reuse bool) (net.Conn, error)

func RandAsciiString

func RandAsciiString(n int) string

func RandBetween

func RandBetween(min, max int) int

func ReadWithoutComment

func ReadWithoutComment(file string, commentPrefix string) ([]byte, error)

func Socks5ProxyConnect

func Socks5ProxyConnect(proxyURL *url.URL, conn net.Conn, addr string) error

func Socks5ProxyDial

func Socks5ProxyDial(proxyURL string, addr string, timeout time.Duration) (net.Conn, error)

func TLSConfig

func TLSConfig(domain string) (*tls.Config, error)

func ToBytes

func ToBytes(s string) (uint64, error)

ToBytes parses a string formatted by ByteSize as bytes.

func ToMegabytes

func ToMegabytes(s string) (uint64, error)

ToMegabytes parses a string formatted by ByteSize as megabytes.

func WildcardMatch

func WildcardMatch(text string, pattern string) bool

Types

type BufConn

type BufConn struct {
	net.Conn
	BR *bufio.Reader
}

func NewBufConn

func NewBufConn(c net.Conn, r *bufio.Reader) *BufConn

func (*BufConn) Peek

func (c *BufConn) Peek(n int) ([]byte, error)

func (*BufConn) Read

func (c *BufConn) Read(b []byte) (n int, err error)

func (*BufConn) Reset

func (c *BufConn) Reset(conn net.Conn)

func (*BufConn) Write

func (c *BufConn) Write(b []byte) (n int, err error)

type BufferChunkReader

type BufferChunkReader struct {
	io.Reader
	Err error
}

func (*BufferChunkReader) Read

func (r *BufferChunkReader) Read(p []byte) (int, error)

type DebugReader

type DebugReader struct {
	io.Reader
	Buf bytes.Buffer
}

func (*DebugReader) Read

func (r *DebugReader) Read(p []byte) (int, error)

type HttpPostWriter

type HttpPostWriter struct {
	URL string
}

func (*HttpPostWriter) Write

func (s *HttpPostWriter) Write(p []byte) (n int, err error)

type PeekReader

type PeekReader interface {
	Peek(n int) ([]byte, error)
}

type TimeoutReadWriteCloser

type TimeoutReadWriteCloser struct {
	io.ReadWriteCloser
	// contains filtered or unexported fields
}

func (*TimeoutReadWriteCloser) Read

func (s *TimeoutReadWriteCloser) Read(p []byte) (n int, err error)

func (*TimeoutReadWriteCloser) SetReadDeadline

func (s *TimeoutReadWriteCloser) SetReadDeadline(t time.Time) error

func (*TimeoutReadWriteCloser) SetWriteDeadline

func (s *TimeoutReadWriteCloser) SetWriteDeadline(t time.Time) error

func (*TimeoutReadWriteCloser) Write

func (s *TimeoutReadWriteCloser) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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