Documentation ¶
Index ¶
- Variables
- func BuildStats(scope *stats.Scope, stats interface{}) error
- func CheckPort(port int) bool
- func CheckPortWithReusePort(port int) bool
- func Copy(src map[string]string) map[string]string
- func DurationPtr(d time.Duration) *time.Duration
- func FlattenKey(key string) string
- func GetLocalIP() (string, error)
- func GetPortByRange(start, end int, timeout time.Duration) (int, error)
- func IntMax(a, b int) int
- func IntMin(a, b int) int
- func IsAddrInUse(err error) bool
- func LocateHAProxy() (string, error)
- func NewUUID() (string, error)
- func PickFirstNonEmptyStr(str ...string) string
- func ReadPidFile(pidFile string) (int, error)
- func Round(f float64, digits int) (float64, error)
- func RunCmd(cmd string) (string, error)
- func VerifyTCP4Address(address string) error
- func WithTempDir(f func(d string))
- func WithTempFile(content string, f func(filename string))
- func WriteFileAtomically(filename string, data []byte, perm os.FileMode) error
- type TestServer
- type TestServerHandler
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidHTTPListen indicates that the given address is invalid ErrInvalidHTTPListen = errors.New("invalid TCP4 address") // ErrHTTPListenMissingPort indicates that the given address lack port ErrHTTPListenMissingPort = errors.New("port number must be speified") )
Functions ¶
func BuildStats ¶
BuildStats builds the stats with given scope. It will initialize the Scope, Counter, Gauge, Histogram fields.
Exmaples of struct fields and their initialized value:
// CxTotal value will be *scope.Counter("cx_total") CxTotal *stats.Counter // CxActive value will be *scope.Gauge("cx_active") CxActive *stats.Gauge // CxDuration value will be *scope.Histogram("cx_duration") CxDuration *stats.Histogram
func CheckPortWithReusePort ¶
CheckPortWithReusePort return true if port not bind by other process.
func DurationPtr ¶
DurationPtr return *time.Duration
func FlattenKey ¶
FlattenKey flatten the key for formatting, removes spaces and point.
func GetPortByRange ¶
GetPortByRange return a random port in [start, end) if can not find a unused in timeout will return a error.
func IntMin ¶
IntMin returns the smaller int I can't believe that golang doesn't provide this. Yes, there is math.Min() but giving two int, you have to
math.Min(float64(a), float64(b))
Converting TWO int to FLOAT64 EVERY TIME just to get the smaller one, that's crazy! There should be something like:
a < b ? a : b
or:
a if a < b else b
But there isn't! So I wrote this stupid func along with the above, I must be crazy.
Hi, let's just blame that golang doesn't have generics.
func IsAddrInUse ¶
IsAddrInUse returns whether the given error is known to report that the address is in use. e.g. syscall.EADDRINUSE
func PickFirstNonEmptyStr ¶
PickFirstNonEmptyStr return the first no empty string.
func ReadPidFile ¶
ReadPidFile reads content from given file path and return as a int
func Round ¶
Round round up float to a specific precision. I'm getting a little bit used to this The implementation is dumb but safe hopefully
func VerifyTCP4Address ¶
VerifyTCP4Address returns error if the given address is not a valid TCP4 address. e.g. 1.1.1.1: -> NG
1.1.1.1:1000 -> OK
func WithTempDir ¶
func WithTempDir(f func(d string))
WithTempDir creates a temp dir then run the given callback(tempDir) finally remove the temp dir and any children it contains
func WithTempFile ¶
WithTempFile creates a tempfile with given content then calls f()
The file will be deleted after calling f()
func WriteFileAtomically ¶
WriteFileAtomically is the same as ioutil.WriteFile but it writes atomically by using os.Rename which is atomic as required by POSIX.
Known issue: If the tempfile is write on another drive the rename will fail with EXDEV, in this case atomic write is not possible.
Types ¶
type TestServer ¶
type TestServer struct { *net.TCPListener // contains filtered or unexported fields }
TestServer is a TCP server for testing
func StartTestServer ¶
func StartTestServer(t testing.TB, addr string, handlers ...TestServerHandler) *TestServer
StartTestServer launches a TCP server at given address
func (*TestServer) Close ¶
func (ts *TestServer) Close() error
Close stops listening and wait for all connections to complete
func (*TestServer) Start ¶
func (ts *TestServer) Start() error
Start starts listening on given address
type TestServerHandler ¶
TestServerHandler handles incomming connections.