Documentation ¶
Overview ¶
#### comments with mark
- "//--" debug code
- "//!!" warning
- "//??" important
#### test and benchmark functions
- test instances: TestFunc_t1, TestFunc_t2, TestFunc_t3
- error test: TestFunc_err1, TestFunc_err2, TestFunc_err3
- benchmark instances: BenchmarkFunc_b1, BenchmarkFunc_b2, BenchmarkFunc_b3
Index ¶
- Constants
- Variables
- func AddHttpsScheme(a string) string
- func Base64Decode(src string) ([]byte, error)
- func Base64Encode(src []byte) string
- func BuildInfo(vars ...[2]string) (info [][2]string)
- func DelayFunc(delay int64) http.HandlerFunc
- func EqualVector[T constraints.Ordered](arr1, arr2 []T) (ok bool)
- func FileSaveName(p string) (out string, err error)
- func FileSize2Str(n int64) string
- func GetOClock(shift int) (clock time.Time)
- func GetPanic(n int)
- func HttpErrorExtract(err error) error
- func HttpErrorResetCode(err error, code uint, codes ...int) (ok bool)
- func ListenOSIntr(do func(), errch chan<- error, sgs ...os.Signal)
- func NewRand() (rd *rand.Rand)
- func ParseDate(value string) (at time.Time, err error)
- func ParseDatetime(value string) (at time.Time, err error)
- func PrintJSON(d interface{}) (err error)
- func ProjectDir() (dir string, err error)
- func ProjectFile(p2f ...string) (fp string, err error)
- func QuoteString(str string) string
- func ResBadRequest(writer http.ResponseWriter, code int, err error)
- func ResJSON(writer http.ResponseWriter, data interface{}, errs ...error)
- func ResOk(writer http.ResponseWriter)
- func SetLogRFC3339()
- func SimplifyDebugStack(bts []byte, n int) string
- func StrsIndex(ss []string, s string) (i int)
- func TimeCeil(at time.Time, tu string) (out time.Time, err error)
- func TimeFloor(at time.Time, tu string) (out time.Time, err error)
- func UniqVector[T constraints.Ordered](arr []T) (list []T)
- func VectorIndex[T constraints.Ordered](list []T, v T) int
- func WrapError(err error, skips ...int) error
- type ErrContainer
- type Error
- type Executor
- type HttpError
- type NetworkTimeResult
- type NetworkTimeServer
- type PX
- type Pprof
- type ResData
- type Result
- type Vector
Constants ¶
const (
RFC3339ms = "2006-01-02T15:04:05.000Z07:00"
)
Variables ¶
var (
Rand *rand.Rand
)
/
Functions ¶
func DelayFunc ¶
func DelayFunc(delay int64) http.HandlerFunc
func EqualVector ¶
func EqualVector[T constraints.Ordered](arr1, arr2 []T) (ok bool)
func FileSaveName ¶
func FileSize2Str ¶
func HttpErrorExtract ¶
func ParseDatetime ¶
datetime format: "2021-06-24 09:10:11"
func ProjectDir ¶
get root path of project by recursively match go.mod in parent directory
func ProjectFile ¶
func ResBadRequest ¶
func ResBadRequest(writer http.ResponseWriter, code int, err error)
func ResJSON ¶
func ResJSON(writer http.ResponseWriter, data interface{}, errs ...error)
?? data is ResData
func ResOk ¶
func ResOk(writer http.ResponseWriter)
func SimplifyDebugStack ¶
func TimeCeil ¶
ceil time, e.g. TimeCeil('2020-12-01T17:39:07.123+08:00', "M") -> '2020-12-01T17:40:00+08:00'
valid unit(key or value) H: hour, M: minute, S: second y: year, s: season, m: month, w: week, d: day
func TimeFloor ¶
floor time, e.g. TimeFloor('2020-12-01T17:39:07.123+08:00', "M") -> '2020-12-01T17:39:00+08:00'
valid unit(key or value) H: hour, M: minute, S: second y: year, s: season, m: month, w: week, d: day
func UniqVector ¶
func UniqVector[T constraints.Ordered](arr []T) (list []T)
func VectorIndex ¶
func VectorIndex[T constraints.Ordered](list []T, v T) int
Types ¶
type ErrContainer ¶
type ErrContainer struct {
// contains filtered or unexported fields
}
func NewErrContainer ¶
func NewErrContainer(value interface{}, errmsg string) (ec *ErrContainer)
func (*ErrContainer) Error ¶
func (ec *ErrContainer) Error() string
func (*ErrContainer) Level ¶
func (ec *ErrContainer) Level() (level int)
func (*ErrContainer) SetLevel ¶
func (ec *ErrContainer) SetLevel(level int) *ErrContainer
func (*ErrContainer) Value ¶
func (ec *ErrContainer) Value() (value interface{})
type Error ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
func NewExecutor ¶
func NewExecutor() *Executor
type HttpError ¶
type HttpError struct { Raw error `json:"raw"` // program error for debug Message string `json:"message"` // message for frontend HttpCode int `json:"httpCode"` // http response status code Code int `json:"code"` // bussiness logical code }
models return a error which will treated as a response to gin.Context
func NewHttpError ¶
type NetworkTimeResult ¶
type NetworkTimeResult struct { T1 time.Time `json:"t1"` T2 time.Time `json:"t2"` T3 time.Time `json:"t3"` T4 time.Time `json:"t4"` Sigma int64 `json:"sigma"` Delta int64 `json:"delta"` }
func GetNetworkTime ¶
func GetNetworkTime(addr string, delay int64) (result *NetworkTimeResult, err error)
func (NetworkTimeResult) String ¶
func (result NetworkTimeResult) String() string
type NetworkTimeServer ¶
https://en.wikipedia.org/wiki/Network_Time_Protocol https://en.wikipedia.org/wiki/File:NTP-Algorithm.svg
func NewNetworkTimeServer ¶
func NewNetworkTimeServer(addr string, delay int64) (ser *NetworkTimeServer, err error)
func (*NetworkTimeServer) Run ¶
func (ser *NetworkTimeServer) Run() error
type Pprof ¶
web browser address
http://localhost:5060/debug/pprof/
get profiles and view in browser
$ go tool pprof -http=:8080 http://localhost:5060/debug/pprof/allocs?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/block?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/goroutine?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/heap?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/mutex?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/profile?seconds=30 $ go tool pprof http://localhost:5060/debug/pprof/threadcreate?seconds=30
download profile file and convert to svg image
$ wget -O profile.out localhost:5060/debug/pprof/profile?seconds=30 $ go tool pprof -svg profile.out > profile.svg
get pprof in 30 seconds and save to svg image
$ go tool pprof -svg http://localhost:5060/debug/pprof/allocs?seconds=30 > allocs.svg
get trace in 5 seconds
$ wget -O trace.out http://localhost:5060/debug/pprof/trace?seconds=5 $ go tool trace trace.out
get cmdline and symbol binary data
$ wget -O cmdline.out http://localhost:5060/debug/pprof/cmdline $ wget -O symbol.out http://localhost:5060/debug/pprof/symbol