当前位置: 首页>>代码示例>>Golang>>正文


Golang logs.Debug函数代码示例

本文整理汇总了Golang中github.com/quorumsco/logs.Debug函数的典型用法代码示例。如果您正苦于以下问题:Golang Debug函数的具体用法?Golang Debug怎么用?Golang Debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AllowKnownOrigin

// Compares the request's origin with a list of defined origins and allows it if one of them matches
func AllowKnownOrigin(w http.ResponseWriter, req *http.Request) {
	headerOrigin := req.Header.Get("Origin")
	if headerOrigin != "" {
		addr := strings.Split(req.RemoteAddr, ":")[0]
		for _, srcOrigin := range KnownOrigins {
			if srcOrigin == headerOrigin {
				logs.Debug("Match : %s - %s", srcOrigin, headerOrigin)
				w.Header().Set("Access-Control-Allow-Origin", headerOrigin)
				return
			}

			originAddr, err := net.LookupHost(srcOrigin)
			var origin string
			if err == nil {
				origin = originAddr[0]
			} else {
				origin = srcOrigin
			}
			if origin == addr {
				logs.Debug("Match : %s - %s", addr, origin)
				w.Header().Set("Access-Control-Allow-Origin", headerOrigin)
				return
			}
		}
	}
	w.Header().Set("Access-Control-Allow-Origin", "https://cloud.quorumapps.com")
}
开发者ID:quorumsco,项目名称:gateway,代码行数:28,代码来源:session.go

示例2: index

// Index indexes a contact into elasticsearch
func index(Contact *models.Contact, s *elastic.Client) error {
	id := strconv.Itoa(int(Contact.ID))
	if id == "" {
		logs.Error("id is nil")
		return errors.New("id is nil")
	}

	if Contact.Address.Longitude == "null" || Contact.Address.Latitude == "null" {
		logs.Debug("Could not index contact %s", id)
		return nil
	}

	if Contact.Address.Latitude != "" && Contact.Address.Longitude != "" {
		Contact.Address.Location = fmt.Sprintf("%s,%s", Contact.Address.Latitude, Contact.Address.Longitude)
	}

	_, err := s.Index().
		Index("contacts").
		Type("contact").
		Id(id).
		BodyJson(Contact).
		Do()
	if err != nil {
		logs.Critical(err)
		return err
	}

	logs.Debug("Contact %s indexed", id)

	return nil
}
开发者ID:quorumsco,项目名称:indexor,代码行数:32,代码来源:main.go

示例3: DeleteAllFormdata

// DeleteFormdata calls the Delete method from Contacts via RPC (Formdata client). Returns results via jsonapi.
func DeleteAllFormdata(w http.ResponseWriter, r *http.Request) {
	logs.Debug("DeleteAllFormdata")

	form_id, err := strconv.Atoi(router.Context(r).Param("form_id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"form_id": "not integer"}, http.StatusBadRequest)
		return
	}
	contact_id, err := strconv.Atoi(router.Context(r).Param("contact_id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"contact_id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		args          = models.FormdataArgs{Formdata: &models.Formdata{GroupID: router.Context(r).Env["GroupID"].(uint)}}
		reply         = models.FormdataReply{}
	)
	//args.Formdata.ID = uint(id)
	args.Formdata.FormID = uint(form_id)
	args.Formdata.ContactID = uint(contact_id)

	err = contactClient.Call("Formdata.DeleteAll", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, nil, http.StatusNoContent)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:34,代码来源:contacts.go

示例4: DeleteGroup

// DeleteGroup calls the GroupSQL Delete method and returns the results
func DeleteGroup(w http.ResponseWriter, r *http.Request) {
	var (
		groupID int

		err error
	)
	if groupID, err = strconv.Atoi(router.Context(r).Param("id")); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		db         = getDB(r)
		groupStore = models.GroupStore(db)
		g          = &models.Group{ID: uint(groupID)}
	)
	if err = groupStore.Delete(g); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	w.Header().Set("Content-Type", "text/plain")
	Success(w, r, nil, http.StatusNoContent)
}
开发者ID:gofmt,项目名称:oauth2,代码行数:27,代码来源:groups.go

示例5: createFact

func createFact(contact *models.Contact, client *elastic.Client, db *gorm.DB) error {
	Fact := &models.Fact{}
	Fact.GroupID = 1
	Fact.Action.Name = "init"
	Fact.Action.Pitch = "initialise la table de faits"
	Fact.Action.TypeData = "aucune"
	Fact.Status = "init"

	Fact.ContactID = contact.ID

	Fact, err := storeFact(Fact, db)
	if err != nil {
		return err
	}

	if Fact.Contact.ID == 0 {
		logs.Debug("Contact %d didn't exist. Fact %d may therefore be incorrect", contact.ID, Fact.ID)
	}

	err = indexFact(*Fact, client)
	if err != nil {
		return err
	}

	logs.Debug("Fact %d created and indexed", Fact.ID)

	return nil
}
开发者ID:quorumsco,项目名称:indexor,代码行数:28,代码来源:main.go

示例6: DeleteTag

// DeleteTag calls the Delete method from Contacts via RPC (Tag client). Returns results via jsonapi.
func DeleteTag(w http.ResponseWriter, r *http.Request) {
	TID, err := strconv.Atoi(router.Context(r).Param("tag_id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"tag_id": "not integer"}, http.StatusBadRequest)
		return
	}
	id, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		args          = models.TagArgs{GroupID: router.Context(r).Env["GroupID"].(uint)}
		reply         = models.TagReply{}
	)
	args.Tag = new(models.Tag)
	args.Tag.ID = uint(TID)
	args.ContactID = uint(id)
	err = contactClient.Call("Tag.Delete", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, nil, http.StatusNoContent)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:31,代码来源:contacts.go

示例7: UpdateGroup

// UpdateGroup calls the GroupSQL Save method and returns the results
func UpdateGroup(w http.ResponseWriter, r *http.Request) {
	var (
		groupID int
		err     error
	)
	if groupID, err = strconv.Atoi(router.Context(r).Param("id")); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		db         = getDB(r)
		groupStore = models.GroupStore(db)
		g          = &models.Group{ID: uint(groupID)}
	)
	if err = groupStore.First(g, g.ID); err != nil {
		Fail(w, r, map[string]interface{}{"group": err.Error()}, http.StatusBadRequest)
		return
	}

	if err = Request(&views.Group{Group: g}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"group": err.Error()}, http.StatusBadRequest)
		return
	}

	if err = groupStore.Save(g); err != nil {
		logs.Error(err)
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, views.Group{Group: g}, http.StatusOK)
}
开发者ID:gofmt,项目名称:oauth2,代码行数:36,代码来源:groups.go

示例8: CreateTag

// CreateTag calls the Create method from Contacts via RPC (Tag client). Returns results via jsonapi.
func CreateTag(w http.ResponseWriter, r *http.Request) {
	var (
		args = models.TagArgs{GroupID: router.Context(r).Env["GroupID"].(uint)}
	)
	args.Tag = new(models.Tag)
	CID, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}
	args.ContactID = uint(CID)

	if err := Request(&views.Tag{Tag: args.Tag}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"tag": err.Error()}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		reply         = models.TagReply{}
	)
	err = contactClient.Call("Tag.Create", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, views.Tag{Tag: reply.Tag}, http.StatusOK)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:32,代码来源:contacts.go

示例9: CreateFormdata

// CreateFormdata calls the Create method from Contacts via RPC (Formdata client). Returns results via jsonapi.
func CreateFormdata(w http.ResponseWriter, r *http.Request) {
	var (
		args = models.FormdataArgs{Formdata: &models.Formdata{GroupID: router.Context(r).Env["GroupID"].(uint)}}
	)
	CID, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}
	args.Formdata.ContactID = uint(CID)

	if err := Request(&views.Formdata{Formdata: args.Formdata}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"formdata": err.Error()}, http.StatusBadRequest)
		return
	}
	date := time.Now()
	args.Formdata.Date = &date

	var (
		contactClient = rpcClient(r, "ContactClient")
		reply         = models.FormdataReply{}
	)
	err = contactClient.Call("Formdata.Create", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, views.Formdata{Formdata: reply.Formdata}, http.StatusOK)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:33,代码来源:contacts.go

示例10: Authenticate

// Middleware that takes care of the authentication. If the token is not correct or there is no token, an error is returned
func Authenticate(h http.Handler) http.Handler {
	fn := func(w http.ResponseWriter, r *http.Request) {
		// Pour desactiver l'authentification
		// router.Context(r).Env["GroupID"] = uint(1)
		// router.Context(r).Env["UserID"] = uint(1)
		// h.ServeHTTP(w, r)
		// return
		//
		token := strings.TrimLeft(r.Header.Get("Authorization"), "Bearer ")
		if token == "" {
			logs.Debug("No token found")
			Fail(w, r, "missing bearer authorization token", http.StatusBadRequest)
		} else {
			body, _ := Bearer(r, "OAuth2", "/oauth2/info", token)
			resp := make(map[string]interface{})
			if err := json.Unmarshal(body, &resp); err != nil {
				logs.Error(err)
				Fail(w, r, map[string]string{"Authentication": err.Error()}, http.StatusBadRequest)
				return
			}
			if resp["error"] != nil {
				// refresh := strings.TrimLeft(r.Header.Get("Refresh"), "Refresh ")
				// r.Form = make(url.Values)
				// r.Form.Add("grant_type", "refresh_token")
				// r.Form.Add("refresh_token", refresh)
				// logs.Debug(refresh)
				// body, _ := ServiceBody(PostMethod, r, "OAuth2", "/oauth2/token", "application/x-www-form-urlencoded", []byte(r.Form.Encode()))
				// resp := make(map[string]interface{})
				// if err := json.Unmarshal(body, &resp); err != nil {
				// 	logs.Error(err)
				// 	Fail(w, r, map[string]string{"Authentication": err.Error()}, http.StatusBadRequest)
				// 	return
				// }
				// logs.Debug(resp)
				// if resp["error"] != nil {
				logs.Debug("Token expired")
				Fail(w, r, "Token", http.StatusBadRequest)
				// }
			} else {
				s := strings.Split(resp["owner"].(string), ":")
				ID, _ := strconv.Atoi(s[0])
				groupID, _ := strconv.Atoi(s[1])

				router.Context(r).Env["GroupID"] = uint(groupID)
				router.Context(r).Env["UserID"] = uint(ID)
				if ID == 0 {
					logs.Error(errors.New("ID is 0, no such user"))
					Fail(w, r, map[string]string{"ID": "is 0"}, http.StatusBadRequest)
					return
				}
				logs.Debug("Authentication done")
				h.ServeHTTP(w, r)
			}
		}
	}
	return http.HandlerFunc(fn)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:58,代码来源:controllers.go

示例11: serve

func serve(ctx *cli.Context) error {
	var err error

	var config settings.Config
	if ctx.String("config") != "" {
		config, err = settings.Parse(ctx.String("config"))
		if err != nil {
			logs.Error(err)
		}
	}

	if config.Debug() {
		logs.Level(logs.DebugLevel)
	}

	dialect, args, err := config.SqlDB()
	if err != nil {
		logs.Critical(err)
		os.Exit(1)
	}
	logs.Debug("database type: %s", dialect)

	var app = application.New()
	if app.Components["DB"], err = databases.InitGORM(dialect, args); err != nil {
		logs.Critical(err)
		os.Exit(1)
	}
	logs.Debug("connected to %s", args)

	if config.Migrate() {
		app.Components["DB"].(*gorm.DB).AutoMigrate(models.Models()...)
		logs.Debug("database migrated successfully")
	}

	app.Components["Templates"] = views.Templates()
	// app.Components["Mux"] = router.New()
	app.Components["Mux"] = gojimux.New()

	if config.Debug() {
		app.Use(router.Logger)
	}

	app.Use(app.Apply)

	app.Get("/users/register", controllers.Register)
	app.Post("/users/auth", controllers.Auth)
	app.Post("/users/register", controllers.Register)

	server, err := config.Server()
	if err != nil {
		logs.Critical(err)
		os.Exit(1)
	}
	return app.Serve(server.String())
}
开发者ID:quorumsco,项目名称:users,代码行数:55,代码来源:main.go

示例12: UpdateContact

// UpdateContact calls the Update method from Contacts via RPC (Contact client). Returns results via jsonapi.
func UpdateContact(w http.ResponseWriter, r *http.Request) {
	id, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		args = models.ContactArgs{Contact: &models.Contact{GroupID: router.Context(r).Env["GroupID"].(uint)}}
	)

	if err := Request(&views.Contact{Contact: args.Contact}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"contact": err.Error()}, http.StatusBadRequest)
		return
	}
	var coordonnees [2]string = Geoloc(&args)
	if coordonnees[0] == "noresponse" {
		err := errors.New("noresponse")
		Error(w, r, err.Error(), http.StatusBadRequest)
		return
	}
	args.Contact.Address.Latitude = coordonnees[0]
	args.Contact.Address.Longitude = coordonnees[1]

	var (
		contactClient = rpcClient(r, "ContactClient")
		reply         = models.ContactReply{}
	)
	args.Contact.ID = uint(id)

	err = contactClient.Call("Contact.Update", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	rep := models.ContactReply{}
	args.Contact = reply.Contact

	err = contactClient.Call("Search.Index", args, &rep)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}
	Success(w, r, views.Contact{Contact: reply.Contact}, http.StatusOK)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:49,代码来源:contacts.go

示例13: LoadAccess

// Returns a storage session
func (s *RedisStorage) LoadAccess(code string) (*osin.AccessData, error) {
	logs.Debug("LoadAccess: %s", code)

	d_map, err := s.client.HGetAllMap(code).Result()
	if len(d_map) == 0 || err != nil {
		return nil, errors.New("Authorize not found")
	}

	client, err := s.getClient(d_map["client"])
	if err != nil {
		return nil, err
	}
	expires_in, _ := strconv.Atoi(d_map["expires_in"])
	created_at := new(time.Time)
	created_at.UnmarshalBinary([]byte(d_map["created_at"]))

	d := &osin.AccessData{
		Client:      client,
		ExpiresIn:   int32(expires_in),
		Scope:       d_map["scope"],
		RedirectUri: d_map["redirect_uri"],
		CreatedAt:   *created_at,
		UserData:    d_map["user_data"],
	}
	return d, nil
}
开发者ID:gofmt,项目名称:oauth2,代码行数:27,代码来源:redis.go

示例14: SaveAccess

// Saves a new storage session
func (s *RedisStorage) SaveAccess(data *osin.AccessData) error {
	logs.Debug("SaveAccess: %s", data.AccessToken)

	s.access[data.AccessToken] = data
	if data.RefreshToken != "" {
		s.refresh[data.RefreshToken] = data.AccessToken
	}

	binary, _ := data.CreatedAt.MarshalBinary()
	s.client.HMSet(data.AccessToken,
		"client", data.Client.GetId(),
		"expires_in", strconv.Itoa(int(data.ExpiresIn)),
		"scope", data.Scope,
		"redirect_uri", data.RedirectUri,
		"created_at", string(binary),
		"user_data", data.UserData.(string),
	).Result()
	s.client.Expire(data.AccessToken, time.Duration(data.ExpiresIn)*time.Second).Result()
	// s.client.Expire(data.AccessToken, 10*time.Second).Result()

	if data.RefreshToken != "" {
		s.client.Set(data.RefreshToken, data.AccessToken, time.Duration(data.ExpiresIn)*time.Second).Result()
	}

	return nil
}
开发者ID:gofmt,项目名称:oauth2,代码行数:27,代码来源:redis.go

示例15: CreateFact

// CreateFact calls the Create method from Contacts via RPC (Fact client). Returns results via jsonapi.
func CreateFact(w http.ResponseWriter, r *http.Request) {
	var args = models.FactArgs{Fact: &models.Fact{GroupID: router.Context(r).Env["GroupID"].(uint)}}

	if err := Request(&views.Fact{Fact: args.Fact}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"fact": err.Error()}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		reply         = models.FactReply{}
	)
	err := contactClient.Call("Fact.Create", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	args.Fact = reply.Fact

	err = contactClient.Call("Search.IndexFact", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, views.Fact{Fact: reply.Fact}, http.StatusOK)
}
开发者ID:quorumsco,项目名称:gateway,代码行数:30,代码来源:contacts.go


注:本文中的github.com/quorumsco/logs.Debug函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。