本文整理汇总了Golang中github.com/apex/log.Interface类的典型用法代码示例。如果您正苦于以下问题:Golang Interface类的具体用法?Golang Interface怎么用?Golang Interface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewGameHub
// NewGameHub creates a new GameHub for a given log contenxt.
func NewGameHub(ctx log.Interface) GameHub {
return GameHub{
Log: ctx.WithField("module", "GameHub"),
games: make(map[string]Game),
register: make(chan GameRegistrationRequest),
}
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:8,代码来源:game_hub.go
示例2: GetHandlerManager
// GetHandlerManager gets a new HandlerManager for ttnctl
func GetHandlerManager(ctx log.Interface, appID string) (*grpc.ClientConn, *handler.ManagerClient) {
ctx.WithField("Handler", viper.GetString("handler-id")).Info("Discovering Handler...")
dscConn, client := GetDiscovery(ctx)
defer dscConn.Close()
handlerAnnouncement, err := client.Get(GetContext(ctx), &discovery.GetRequest{
ServiceName: "handler",
Id: viper.GetString("handler-id"),
})
if err != nil {
ctx.WithError(errors.FromGRPCError(err)).Fatal("Could not find Handler")
}
token := TokenForScope(ctx, scope.App(appID))
ctx.WithField("Handler", handlerAnnouncement.NetAddress).Info("Connecting with Handler...")
hdlConn, err := handlerAnnouncement.Dial()
if err != nil {
ctx.WithError(err).Fatal("Could not connect to Handler")
}
managerClient, err := handler.NewManagerClient(hdlConn, token)
if err != nil {
ctx.WithError(err).Fatal("Could not create Handler Manager")
}
return hdlConn, managerClient
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:26,代码来源:handler.go
示例3: SetApp
// SetApp stores the app ID and app EUI preferences
func SetApp(ctx log.Interface, appID string, appEUI types.AppEUI) {
config := readData(appFilename)
config[idKey] = appID
config[euiKey] = appEUI.String()
err := writeData(appFilename, config)
if err != nil {
ctx.WithError(err).Fatal("Could not save app preference")
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:10,代码来源:config.go
示例4: ForceRefreshToken
// ForceRefreshToken forces a refresh of the access token
func ForceRefreshToken(ctx log.Interface) {
tokenSource := GetTokenSource(ctx).(*ttnctlTokenSource)
token, err := tokenSource.Token()
if err != nil {
ctx.WithError(err).Fatal("Could not get access token")
}
token.Expiry = time.Now().Add(-1 * time.Second)
tokenSource.source = oauth2.ReuseTokenSource(token, getAccountServerTokenSource(token))
tokenSource.Token()
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:11,代码来源:account.go
示例5: NewGateway
// NewGateway creates a new in-memory Gateway structure
func NewGateway(ctx log.Interface, id string) *Gateway {
ctx = ctx.WithField("GatewayID", id)
return &Gateway{
ID: id,
Status: NewStatusStore(),
Utilization: NewUtilization(),
Schedule: NewSchedule(ctx),
Ctx: ctx,
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:11,代码来源:gateway.go
示例6: NewGameState
// NewGameState creates a new game state given a logging context.
func NewGameState(ctx log.Interface) GameState {
return GameState{
Users: make(map[*User]bool),
Shots: make(map[*Shot]bool),
Log: ctx.WithField("module", "GameState"),
UpdateInterval: DefaultStateUpdateLoopInterval,
simulate: make(chan []Command),
updateState: make(chan *GameState),
}
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:11,代码来源:game_state.go
示例7: saveToken
func saveToken(ctx log.Interface, token *oauth2.Token) {
data, err := json.Marshal(token)
if err != nil {
ctx.WithError(err).Fatal("Could not save access token")
}
err = GetTokenCache().Set(tokenName(), data)
if err != nil {
ctx.WithError(err).Fatal("Could not save access token")
}
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:10,代码来源:account.go
示例8: GetAccount
// GetAccount gets a new Account server client for ttnctl
func GetAccount(ctx log.Interface) *account.Account {
token, err := GetTokenSource(ctx).Token()
if err != nil {
ctx.WithError(err).Fatal("Could not get access token")
}
server := viper.GetString("auth-server")
manager := GetTokenManager(token.AccessToken)
return account.NewWithManager(server, token.AccessToken, manager).WithHeader("User-Agent", GetUserAgent())
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:12,代码来源:account.go
示例9: NewServer
// NewServer sets up a new server instance.
func NewServer(ctx log.Interface, address, templateFilename string) Server {
return Server{
Log: ctx.WithFields(log.Fields{
"module": "Server",
"address": address,
}),
IndexTemplate: template.Must(template.ParseFiles(templateFilename)),
Address: address,
Hub: NewGameHub(ctx),
}
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:12,代码来源:server.go
示例10: NewUser
// NewUser creates a new user with a new Gopher to manage the user's new ws
// connection.
func NewUser(ctx log.Interface, ws *websocket.Conn) User {
id := uuid.NewRandom().String()[:3]
return User{
ID: id,
Gopher: NewGopher(id, RandomCoordinates(boardSize)),
Log: ctx.WithField("module", "User"),
send: make(chan []byte, 256),
ws: ws,
}
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:13,代码来源:user.go
示例11: TokenForScope
func TokenForScope(ctx log.Interface, scope string) string {
token, err := GetTokenSource(ctx).Token()
if err != nil {
ctx.WithError(err).Fatal("Could not get token")
}
restricted, err := GetTokenManager(token.AccessToken).TokenForScope(scope)
if err != nil {
ctx.WithError(err).Fatal("Could not get correct rights")
}
return restricted
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:13,代码来源:account.go
示例12: GetContext
// GetContext returns a new context
func GetContext(ctx log.Interface, extraPairs ...string) context.Context {
token, err := GetTokenSource(ctx).Token()
if err != nil {
ctx.WithError(err).Fatal("Could not get token")
}
md := metadata.Pairs(
"id", GetID(),
"service-name", "ttnctl",
"service-version", fmt.Sprintf("%s-%s (%s)", viper.GetString("version"), viper.GetString("gitCommit"), viper.GetString("buildDate")),
"token", token.AccessToken,
)
return metadata.NewContext(context.Background(), md)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:14,代码来源:context.go
示例13: GetDiscovery
// GetDiscovery gets the Discovery client for ttnctl
func GetDiscovery(ctx log.Interface) (*grpc.ClientConn, discovery.DiscoveryClient) {
path := path.Join(GetDataDir(), "/ca.cert")
cert, err := ioutil.ReadFile(path)
if err == nil && !api.RootCAs.AppendCertsFromPEM(cert) {
ctx.Warnf("Could not add root certificates from %s", path)
}
conn, err := api.Dial(viper.GetString("discovery-address"))
if err != nil {
ctx.WithError(err).Fatal("Could not connect to Discovery server")
}
return conn, discovery.NewDiscoveryClient(conn)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:14,代码来源:discovery.go
示例14: GetAppID
// GetAppID returns the AppID that must be set in the command options or config
func GetAppID(ctx log.Interface) string {
appID := viper.GetString("app-id")
if appID == "" {
appData := readData(appFilename)
id, ok := appData[idKey].(string)
if !ok {
ctx.Fatal("Invalid appID in config file.")
}
appID = id
}
if appID == "" {
ctx.Fatal("Missing AppID. You should select an application to use with \"ttnctl applications select\"")
}
return appID
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:17,代码来源:config.go
示例15: NewGame
// NewGame creates a new game instance.
func NewGame(ctx log.Interface, id string) Game {
gs := NewGameState(ctx)
cp := NewCommandProcessor(&gs)
return Game{
Log: ctx.WithFields(log.Fields{
"module": "Game",
"id": id,
}),
State: &gs,
CommandProcessor: &cp,
register: make(chan *User),
unregister: make(chan *User),
commands: make(chan Command),
}
}
开发者ID:wyattjoh,项目名称:spacegophers,代码行数:17,代码来源:game.go
示例16: GetRouterManager
// GetRouterManager starts a management connection with the router
func GetRouterManager(ctx log.Interface) (*grpc.ClientConn, router.RouterManagerClient) {
ctx.Info("Discovering Router...")
dscConn, client := GetDiscovery(ctx)
defer dscConn.Close()
routerAnnouncement, err := client.Get(GetContext(ctx), &discovery.GetRequest{
ServiceName: "router",
Id: viper.GetString("router-id"),
})
if err != nil {
ctx.WithError(errors.FromGRPCError(err)).Fatal("Could not get Router from Discovery")
}
ctx.Info("Connecting with Router...")
rtrConn, err := routerAnnouncement.Dial()
if err != nil {
ctx.WithError(err).Fatal("Could not connect to Router")
}
ctx.Info("Connected to Router")
return rtrConn, router.NewRouterManagerClient(rtrConn)
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:20,代码来源:router.go
示例17: getStoredToken
func getStoredToken(ctx log.Interface) *oauth2.Token {
tokenCache := GetTokenCache()
data, err := tokenCache.Get(tokenName())
if err != nil {
ctx.WithError(err).Fatal("Could not read stored token")
}
if data == nil {
ctx.Fatal("No account information found. Please login with ttnctl user login [access code]")
}
token := &oauth2.Token{}
err = json.Unmarshal(data, token)
if err != nil {
ctx.Fatal("Account information invalid. Please login with ttnctl user login [access code]")
}
return token
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:17,代码来源:account.go
示例18: GetAppEUI
// GetAppEUI returns the AppEUI that must be set in the command options or config
func GetAppEUI(ctx log.Interface) types.AppEUI {
appEUIString := viper.GetString("app-eui")
if appEUIString == "" {
appData := readData(appFilename)
eui, ok := appData[euiKey].(string)
if !ok {
ctx.Fatal("Invalid AppEUI in config file")
}
appEUIString = eui
}
if appEUIString == "" {
ctx.Fatal("Missing AppEUI. You should select an application to use with \"ttnctl applications select\"")
}
eui, err := types.ParseAppEUI(appEUIString)
if err != nil {
ctx.WithError(err).Fatal("Invalid AppEUI")
}
return eui
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:22,代码来源:config.go
示例19: work
func work(ctx log.Interface) (err error) {
path := "Readme.md"
defer ctx.WithField("path", path).Trace("opening").Stop(&err)
_, err = os.Open(path)
return
}
开发者ID:leobcn,项目名称:log,代码行数:6,代码来源:trace.go
示例20: ConvertFromLoRaWAN
func (h *handler) ConvertFromLoRaWAN(ctx log.Interface, ttnUp *pb_broker.DeduplicatedUplinkMessage, appUp *types.UplinkMessage) error {
// Find Device
dev, err := h.devices.Get(ttnUp.AppId, ttnUp.DevId)
if err != nil {
return err
}
// Check for LoRaWAN
if lorawan := ttnUp.ProtocolMetadata.GetLorawan(); lorawan == nil {
return errors.NewErrInvalidArgument("Activation", "does not contain LoRaWAN metadata")
}
// LoRaWAN: Unmarshal Uplink
var phyPayload lorawan.PHYPayload
err = phyPayload.UnmarshalBinary(ttnUp.Payload)
if err != nil {
return err
}
macPayload, ok := phyPayload.MACPayload.(*lorawan.MACPayload)
if !ok {
return errors.NewErrInvalidArgument("Uplink", "does not contain a MAC payload")
}
macPayload.FHDR.FCnt = ttnUp.ProtocolMetadata.GetLorawan().FCnt
appUp.FCnt = macPayload.FHDR.FCnt
ctx = ctx.WithField("FCnt", appUp.FCnt)
// LoRaWAN: Validate MIC
ok, err = phyPayload.ValidateMIC(lorawan.AES128Key(dev.NwkSKey))
if err != nil {
return err
}
if !ok {
return errors.NewErrNotFound("device that validates MIC")
}
// LoRaWAN: Decrypt
if macPayload.FPort != nil && *macPayload.FPort != 0 && len(macPayload.FRMPayload) == 1 {
appUp.FPort = *macPayload.FPort
ctx = ctx.WithField("FCnt", appUp.FPort)
if err := phyPayload.DecryptFRMPayload(lorawan.AES128Key(dev.AppSKey)); err != nil {
return errors.NewErrInternal("Could not decrypt payload")
}
if len(macPayload.FRMPayload) == 1 {
payload, ok := macPayload.FRMPayload[0].(*lorawan.DataPayload)
if !ok {
return errors.NewErrInvalidArgument("Uplink FRMPayload", "must be of type *lorawan.DataPayload")
}
appUp.PayloadRaw = payload.Bytes
}
}
// LoRaWAN: Publish ACKs as events
if macPayload.FHDR.FCtrl.ACK {
h.mqttEvent <- &types.DeviceEvent{
AppID: appUp.AppID,
DevID: appUp.DevID,
Event: types.DownlinkAckEvent,
}
}
return nil
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:63,代码来源:convert_lorawan.go
注:本文中的github.com/apex/log.Interface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论