Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["context.go"],
importpath = "go-common/library/net/rpc/context",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,53 @@
package context
import (
ctx "context"
"time"
)
// Context web context interface
type Context interface {
ctx.Context
// Now get current time.
Now() time.Time
// Seq implement Context method Seq.
Seq() uint64
// ServiceMethod implement Context method ServiceMethod.
ServiceMethod() string
// User get caller user.
User() string
}
type rpcCtx struct {
ctx.Context
now time.Time
seq uint64
serviceMethod string
user string
}
// NewContext new a rpc context.
func NewContext(c ctx.Context, m, u string, s uint64) Context {
rc := &rpcCtx{Context: c, now: time.Now(), seq: s, serviceMethod: m, user: u}
return rc
}
func (c *rpcCtx) Seq() uint64 {
return c.seq
}
func (c *rpcCtx) ServiceMethod() string {
return c.serviceMethod
}
func (c *rpcCtx) Now() time.Time {
return c.now
}
func (c *rpcCtx) User() string {
return c.user
}