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


Golang log.Error函數代碼示例

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


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

示例1: CreateApplicationHandler

func (a *ApplicationController) CreateApplicationHandler(c *gin.Context) {
	body := &ApplicationModel{}

	if err := c.Bind(body); err != nil {
		log.Error(RestError(c, err))
		return
	}

	if body.Name == "" {
		log.Error(RestErrorInvalidBody(c))
		return
	}

	email := ApiUser(c).Email
	app := models.JSON{
		db.ID_FIELD:         body.Id,
		db.NAME_FIELD:       body.Name,
		db.OWNER_FIELD:      email,
		db.MASTER_KEY_FIELD: strings.ToUpper(utils.GetCleanUUID()),
	}

	appId, err := a.DbService.CreateApp(email, app)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	RespondId(appId, c)
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:29,代碼來源:application.go

示例2: registerUser

func (a *AuthController) registerUser(c *gin.Context, isApp bool) {
	var u models.JSON

	if err := c.Bind(&u); err != nil {
		log.Error(RestErrorInvalidBody(c))
		return
	}

	hashedPassword, err := bcrypt.GenerateFromPassword([]byte(u[db.PASSWORD_FIELD].(string)), 10)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	user := models.JSON{
		db.EMAIL_FIELD:         u[db.EMAIL_FIELD],
		db.PASSWORD_FIELD:      hashedPassword,
		db.REGISTERED_AT_FIELD: time.Now(),
	}

	if isApp {
		user[db.APP_ID_FIELD] = c.Param(APP_ID_PARAM)
	} else {
		user[db.APPS_FIELD] = []interface{}{}
	}

	err = a.DbService.CreateUser(user, isApp)
	if err != nil {
		log.Error(RestError(c, err))
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:31,代碼來源:auth.go

示例3: authorizeMiddleware

func authorizeMiddleware(stop bool) gin.HandlerFunc {
	return func(c *gin.Context) {
		authHeader := c.Request.Header.Get("Authorization")

		if authHeader != "" {
			authHeaderParts := strings.SplitN(authHeader, " ", 2)
			if len(authHeaderParts) != 2 {
				log.Error(RestErrorUnauthorized(c))
				return
			}

			authType := strings.ToLower(authHeaderParts[0])
			authValue := authHeaderParts[1]

			//TODO: authorization for master token, master key, normal token, app id only
			var token *jwt.Token
			var err error
			user := &apiUser{}
			if authType == "bearer" {
				token, err = authWithToken(c, authValue)
				if err == nil {
					user.Email = token.Claims["user"].(string)
					user.InApp = token.Claims["inApp"].(bool)
					user.Master = !user.InApp //we can use the token instead of a master key
					user.Key = authValue
				}
			} else if authType == "masterkey" {
				email, err := authWithMaster(c, authValue)
				if err == nil {
					user.Email = email
					user.InApp = false
					user.Master = true
					user.Key = authValue
				}
			} else {
				c.Next()
				return
			}

			c.Set("user", user)

			if err != nil {
				log.Error(RestError(c, err))
				return
			}

			c.Next()
		} else {
			if !stop {
				c.Next()
			} else {
				log.Error(RestErrorUnauthorized(c))
			}
		}
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:56,代碼來源:middleware.go

示例4: handlePublish

func (p WsMessageReceiver) handlePublish(im interceptorMessage, msg *gowamp.Publish) (interface{}, error) {

	if string(msg.Topic) == "wamp.session.on_leave" {
		args := msg.Arguments
		if len(args) == 0 {
			return nil, nil
		}

		if leavingSessionId, ok := args[0].(gowamp.ID); ok {
			log.Info("Broadcasting session leave:", leavingSessionId)
			p.broadcaster.Broadcast(leavingSessionId)
			return nil, nil
		}

		log.Info("Leave:", args)
		return nil, nil
	}

	if string(msg.Topic) == "wamp.session.on_join" {
		return nil, nil
	}

	if len(msg.Arguments) == 0 {
		return nil, nil
	}

	m, ok := msg.Arguments[0].(string)
	if !ok {
		m = models.String(msg.Arguments[0])
	}

	var clientMessage messaging.Message
	converError := clientMessage.FromString(m)
	if converError != nil {
		log.Error(converError)
		return nil, converError
	}

	if clientMessage.Origin == messaging.ORIGIN_API {
		return nil, nil
	}

	log.Info("Websocket message received:", clientMessage)
	data, apiError := p.ClientProcessor.Process(clientMessage)
	if apiError != nil {
		log.Error(apiError)
	}

	return data, apiError
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:50,代碼來源:wsMessageReceiver.go

示例5: makeErrorResult

func (p RpcMessageReceiver) makeErrorResult(err error) *gowamp.CallResult {
	log.Error(err)
	return &gowamp.CallResult{
		Err:  gowamp.URI(err.Error()),
		Args: []interface{}{err},
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:7,代碼來源:rpcMessageReceiver.go

示例6: NewWebSocketServer

func NewWebSocketServer() (*gowamp.WebsocketServer, *gowamp.Client, *wsInterceptor, error) {
	interceptor := NewWsInterceptor()

	r := gowamp.Realm{}
	r.Interceptor = interceptor

	realms := map[string]gowamp.Realm{}
	realms[config.CONST_DEFAULT_REALM] = r
	wsServer, err := gowamp.NewWebsocketServer(realms)
	if err != nil {
		return nil, nil, nil, err
	}

	wsServer.Upgrader.CheckOrigin = func(r *http.Request) bool {
		//allow connections from any origin
		return true
	}

	c, err := wsServer.GetLocalClient(config.CONST_DEFAULT_REALM, nil)
	if err != nil {
		log.Error(err)
		return nil, nil, nil, err
	}

	http.Handle("/", wsServer)
	http.HandleFunc("/_status", func(w http.ResponseWriter, r *http.Request) {
		log.Info("_status check")
		//we are fine
	})

	return wsServer, c, interceptor, nil
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:32,代碼來源:wsServer.go

示例7: validateAppOperationsAuthorizationMiddleware

func validateAppOperationsAuthorizationMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		user := ApiUser(c)
		if user.InApp && !user.Master {
			log.Error(RestErrorUnauthorized(c), user)
			return
		}
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:9,代碼來源:middleware.go

示例8: String

func String(input interface{}) string {
	b, err := json.Marshal(input)
	if err != nil {
		log.Error(err)
		return "{}"
	}

	return string(b)
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:9,代碼來源:json.go

示例9: GetApplicationsHandler

func (a *ApplicationController) GetApplicationsHandler(c *gin.Context) {
	email := ApiUser(c).Email
	apps, err := a.DbService.GetApps(email)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	c.JSON(http.StatusOK, apps)
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:10,代碼來源:application.go

示例10: validateAppPermissionsMiddleware

func validateAppPermissionsMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		user := ApiUser(c)
		if !user.Master {
			log.Error(RestErrorUnauthorized(c), user)
			c.Next()
			return
		}
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:10,代碼來源:middleware.go

示例11: DeleteType

func (t *TypesController) DeleteType(c *gin.Context) {
	appId := c.Param("appId")
	typeName := c.Param("typeName")

	err := t.DbService.DeleteAllItems(appId, typeName)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:10,代碼來源:types.go

示例12: validateAppMiddleware

func validateAppMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		appId := c.Param("appId")
		log.Info(appId)
		if appId == "" {
			log.Error(RestError(c, "Invalid app id."))
		} else {
			c.Next()
		}
	}
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:11,代碼來源:middleware.go

示例13: GetTypesHandler

func (t *TypesController) GetTypesHandler(c *gin.Context) {
	appId := c.Param("appId")

	types, err := t.DbService.GetTypes(appId)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	c.JSON(http.StatusOK, types)
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:11,代碼來源:types.go

示例14: loginUser

func (a *AuthController) loginUser(c *gin.Context, isApp bool) {
	var u UserModel

	if err := c.Bind(&u); err != nil {
		log.Error(RestError(c, err))
		return
	}

	appId := ""
	if isApp {
		appId = c.Param(APP_ID_PARAM)
	}

	user, err := a.DbService.GetUser(u.Email, isApp, appId)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	err = bcrypt.CompareHashAndPassword(user[db.PASSWORD_FIELD].([]byte), []byte(u.Password))
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	token := jwt.New(jwt.GetSigningMethod("HS256"))
	token.Claims["user"] = u.Email
	token.Claims["expiration"] = time.Now().Add(time.Minute + 60).Unix()
	token.Claims["inApp"] = isApp

	tokenStr, err := token.SignedString([]byte(""))

	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	c.JSON(http.StatusOK, models.JSON{
		"token": tokenStr,
	})
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:41,代碼來源:auth.go

示例15: shouldProcessMessage

func (p MessageProcessor) shouldProcessMessage(m Message) bool {
	key := m.GetRedisKey()
	timestamp := p.redisClient.Get(key).Val()
	if timestamp == "" {
		return true
	}

	cachedTime, parseTimeError := time.Parse(time.RFC3339, timestamp)
	if parseTimeError == nil {
		log.Error("Error parsing message time:", parseTimeError)
		return true
	}

	messageTime, parseTimeError := time.Parse(time.RFC3339, m.Timestamp)
	if parseTimeError == nil {
		log.Error("Error parsing message time:", parseTimeError)
		return true
	}

	return cachedTime.Before(messageTime)
}
開發者ID:neutrinoapp,項目名稱:neutrino,代碼行數:21,代碼來源:messageProcessor.go


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