Back to godoc.org
github.com/cjey/gbase

Package gbase

v0.1.0
Latest Go to latest

The highest tagged major version is .

Published: Jul 16, 2020 | License: MIT | Module: github.com/cjey/gbase

Index

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

func GetRealSession

func GetRealSession(ctx Context) string

GetRealSession use to get real session name

func GetSession

func GetSession(ctx Context) string

GetSession use to get session name if it has real session, otherwise return context name instead

func LiveProcessName

func LiveProcessName(ctx Context, interval time.Duration, liveName func(int) string) chan struct{}

LiveProcessName change current process name every interval duration. You can use this for exposing your core runtime information to maintainer.

func NewZapLogger

func NewZapLogger(level, outpath, encoding string, showCaller bool) (*zap.Logger, error)

NewZapLogger return default log style

func ReplaceZapLogger

func ReplaceZapLogger(level, outpath, encoding string, showCaller bool) (func(), error)

ReplaceZapLogger use default log style to replace zap global logger

func ResolveTCPAddr

func ResolveTCPAddr(ctx Context, raw string, defaultPort uint16) (*net.TCPAddr, error)

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

func SetSession(ctx Context, session string)

SetSession use to set real session name

func WriteMyPID

func WriteMyPID(ctx Context, appname string)

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.

type Context

type Context = context.Context

type alias

func NamedContext

func NamedContext(name string) Context

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 SimpleContext

func SimpleContext() Context

SimpleContext return new context without name

func ToNamedContext

func ToNamedContext(gctx gcontext.Context, name string) Context

ToNamedContext return new context use specified official context and name

func ToSessionContext

func ToSessionContext(gctx gcontext.Context) Context

ToSessionContext return new context use specified official context with auto session name that generated by SessionNameGenerator

func ToSimpleContext

func ToSimpleContext(gctx gcontext.Context) Context

ToSimpleContext return new context use specified official context without name

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier