當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Interface類代碼示例

本文整理匯總了Golang中github.com/apex/log.Interface的典型用法代碼示例。如果您正苦於以下問題:Golang Interface類的具體用法?Golang Interface怎麽用?Golang Interface使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Interface類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/apex/log.Interface類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。