Documentation ¶
Index ¶
- Variables
- func GetRealSession(ctx Context) string
- func GetSession(ctx Context) string
- func LiveProcessName(ctx Context, interval time.Duration, liveName func(int) string) chan struct{}
- func NewZapLogger(level, outpath, encoding string, showCaller bool) (*zap.Logger, error)
- func ReplaceZapLogger(level, outpath, encoding string, showCaller bool) (func(), error)
- func ResolveTCPAddr(ctx Context, raw string, defaultPort uint16) (*net.TCPAddr, error)
- func SetSession(ctx Context, session string)
- func WriteMyPID(ctx Context, appname string)
- type Context
Constants ¶
This section is empty.
Variables ¶
var ( BootID = uuid.New().String() BootTime = time.Now() )
var SessionNameGenerator = func() func() string { var counter uint64 return func() string { // return bootid related sequential name const h = "000000000000" var seq = atomic.AddUint64(&counter, 1) var s = strconv.FormatUint(seq, 10) return BootID[:24] + h[:12-len(s)] + s } }()
SessionNameGenerator used to generate session name automatically, you can replace it
Functions ¶
func GetRealSession ¶
GetRealSession use to get real session name
func GetSession ¶
GetSession use to get session name if it has real session, otherwise return context name instead
func LiveProcessName ¶ added in v0.0.5
LiveProcessName change current process name every interval duration. You can use this for exposing your core runtime information to maintainer.
func NewZapLogger ¶
NewZapLogger return default log style
func ReplaceZapLogger ¶
ReplaceZapLogger use default log style to replace zap global logger
func ResolveTCPAddr ¶ added in v0.0.5
ResolveTCPAddr use 0.0.0.0 as default ip to completion the given raw ip "" => 0.0.0.0:defaultPort 80 => 0.0.0.0:80 1.1.1.1 => 1.1.1.1:defaultPort
func SetSession ¶
SetSession use to set real session name
func WriteMyPID ¶ added in v0.0.5
WriteMyPID write current process pid to /var/run/<appname>.pid If write failed, but the file content is equal to current process id, that's also ok. Any error will be ignored.
Types ¶
type Context ¶
type alias
func NamedContext ¶
NamedContext return new context use specified session name
func SessionContext ¶
func SessionContext() Context
SessionContext return new context use auto session name that generated by SessionNameGenerator
func ToNamedContext ¶
ToNamedContext return new context use specified official context and name
func ToSessionContext ¶
ToSessionContext return new context use specified official context with auto session name that generated by SessionNameGenerator
func ToSimpleContext ¶
ToSimpleContext return new context use specified official context without name