• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.Errorf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addPhoto

func addPhoto(fName string, id string, req *http.Request) error {
	ctx := appengine.NewContext(req)

	// DATASTORE
	md, err := retrieveDstore(id, req)
	if err != nil {
		return err
	}
	md.Pictures = append(md.Pictures, fName)
	err = storeDstore(md, req) // removed id in parameter
	if err != nil {
		log.Errorf(ctx, "ERROR addPhoto storeDstore: %s", err)
		return err
	}

	// MEMCACHE
	var mc model
	mc, err = retrieveMemc(id, req)
	if err != nil {
		log.Errorf(ctx, "ERROR addPhoto retrieveMemc: %s", err)
		return err
	}
	mc.Pictures = append(mc.Pictures, fName)
	err = storeMemc(mc, req) // removed id in parameter
	if err != nil {
		log.Errorf(ctx, "ERROR addPhoto storeMemc: %s", err)
		return err
	}

	return nil
}
开发者ID:bpadilla11,项目名称:IntroWebDevS15,代码行数:31,代码来源:photos.go


示例2: Get

func Get(c context.Context, key, def string, values ...interface{}) string {
	configLock.Lock()
	defer configLock.Unlock()
	val, ok := configCache[key]
	if ok {
		return fmt.Sprintf(val, values...)
	}
	value := Value{}
	dskey := datastore.NewKey(c, ConfigName, key, 0, nil)
	err := datastore.Get(c, dskey, &value)
	if err == datastore.ErrNoSuchEntity {
		value.Val = def
		log.Infof(c, "Creating default config for key - %s - default value is - %s", key, value.Val)
		_, err = datastore.Put(c, dskey, &value)
		if err != nil {
			log.Errorf(c, "Error creating default config for key - %s - error is - %v", key, err)
		}
		return fmt.Sprintf(def, values...) // return default, totally new config setting
	}
	if err != nil {
		log.Errorf(c, "Error fetching config for key - %s - error is - %v", key, err)
		return def // error, return the default
	}
	configCache[key] = value.Val
	return fmt.Sprintf(value.Val, values...)
}
开发者ID:mzimmerman,项目名称:appengineconfig,代码行数:26,代码来源:appengineconfig.go


示例3: createUser

func createUser(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	ctx := appengine.NewContext(req)
	hashedPass, err := bcrypt.GenerateFromPassword([]byte(req.FormValue("password")), bcrypt.DefaultCost)
	if err != nil {
		log.Errorf(ctx, "error creating password: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}
	user := User{
		Email:    req.FormValue("email"),
		UserName: req.FormValue("userName"),
		Password: string(hashedPass),
	}
	key := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	key, err = datastore.Put(ctx, key, &user)
	if err != nil {
		log.Errorf(ctx, "error adding todo: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}

	createSession(res, req, user)
	// redirect
	http.Redirect(res, req, "/", 302)
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:25,代码来源:api.go


示例4: index

func index(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)

	id, err := getID(res, req)
	if err != nil {
		log.Errorf(ctx, "getID: %s", err)
		http.Error(res, err.Error(), http.StatusInternalServerError)
		return
	}

	if req.Method == "POST" {
		src, _, err := req.FormFile("data")
		if err != nil {
			log.Errorf(ctx, "ERROR index req.FormFile: %s", err)
			http.Redirect(res, req, `/?id=`+id, http.StatusSeeOther)
			return
		}
		err = uploadPhoto(src, id, req)
		if err != nil {
			log.Errorf(ctx, "ERROR index uploadPhoto: %s", err)
			http.Redirect(res, req, "/logout", http.StatusSeeOther)
			return
		}
	}

	m, err := retrieveMemc(id, req)
	if err != nil {
		log.Errorf(ctx, "ERROR index retrieveMemc: %s", err)
		http.Redirect(res, req, "/logout", http.StatusSeeOther)
		return
	}
	tpl.ExecuteTemplate(res, "index.html", m)
}
开发者ID:mjrmyke,项目名称:GoLangCourse,代码行数:33,代码来源:main.go


示例5: handleAdd

func handleAdd(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	var err error

	if req.Method == "POST" {
		name := strings.TrimSpace(req.FormValue("name"))
		summary, err := getHTML(ctx, req.FormValue("summary"))
		if err != nil {
			http.Error(res, "Server error", http.StatusInternalServerError)
			log.Errorf(ctx, "%v\n", err)
			return
		}

		mov := &movie{
			Name:    name,
			Summary: summary,
			URL:     strings.ToLower(strings.Replace(name, " ", "", -1)),
		}
		err = addMovie(ctx, mov)
		if err != nil {
			http.Error(res, "Server error", http.StatusInternalServerError)
			log.Errorf(ctx, "%v\n", err)
			return
		}
		http.Redirect(res, req, "/", http.StatusSeeOther)
		return
	}

	err = tpl.ExecuteTemplate(res, "addMovie", nil)
	if err != nil {
		http.Error(res, "Server error", http.StatusInternalServerError)
		log.Errorf(ctx, "%v\n", err)
		return
	}
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:35,代码来源:movie.go


示例6: handleUpdate

func handleUpdate(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	var (
		d   int
		day time.Weekday
		err error
	)
	// Check if there is a signed in user.
	u := currentUser(r)
	if u == nil {
		aelog.Errorf(c, "No signed in user for updating")
		goto out
	}
	// Validate XSRF token first.
	if !xsrftoken.Valid(r.PostFormValue(xsrfTokenName), xsrfKey, u.ID, updateURL) {
		aelog.Errorf(c, "XSRF token validation failed")
		goto out
	}
	// Extract the new favorite weekday.
	d, err = strconv.Atoi(r.PostFormValue(favoriteName))
	if err != nil {
		aelog.Errorf(c, "Failed to extract new favoriate weekday: %s", err)
		goto out
	}
	day = time.Weekday(d)
	if day < time.Sunday || day > time.Saturday {
		aelog.Errorf(c, "Got wrong value for favorite weekday: %d", d)
	}
	// Update the favorite weekday.
	updateWeekdayForUser(r, u, day)
out:
	// Redirect to home page to show the update result.
	http.Redirect(w, r, homeURL, http.StatusFound)
}
开发者ID:arasu007,项目名称:identity-toolkit-go,代码行数:34,代码来源:favweekday.go


示例7: handleIndex

func handleIndex(res http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" {
		handleMovieDetails(res, req)
		return
	}

	ctx := appengine.NewContext(req)
	data := struct {
		Movies []movie
	}{}
	m, err := getRecentMovies(ctx, 15)
	if err != nil {
		http.Error(res, "Server error", http.StatusInternalServerError)
		log.Errorf(ctx, "%v\n", err)
		return
	}
	data.Movies = m

	err = tpl.ExecuteTemplate(res, "index", data)
	if err != nil {
		http.Error(res, "Server error", http.StatusInternalServerError)
		log.Errorf(ctx, "%v\n", err)
		return
	}
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:25,代码来源:index.go


示例8: user

func user(res http.ResponseWriter, req *http.Request, ps httprouter.Params) {
	ctx := appengine.NewContext(req)
	user := User{UserName: ps.ByName("user")}
	//get tweets
	tweets, err := getTweets(req, &user)
	if err != nil {
		log.Errorf(ctx, "error getting tweets: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}
	// get session
	memItem, err := getSession(req)
	var sd SessionData
	if err == nil {
		// logged in
		json.Unmarshal(memItem.Value, &sd)
		sd.LoggedIn = true
		sd.ViewingUser = user.UserName
		sd.FollowingUser, err = following(sd.UserName, user.UserName, req)
		if err != nil {
			log.Errorf(ctx, "error running following query: %v", err)
			http.Error(res, err.Error(), 500)
			return
		}
	}
	sd.Tweets = tweets
	tpl.ExecuteTemplate(res, "user.html", &sd)
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:28,代码来源:main.go


示例9: fing

func fing(res http.ResponseWriter, req *http.Request, _ httprouter.Params) {
	ctx := appengine.NewContext(req)
	// get session
	memItem, err := getSession(req)
	if err != nil {
		log.Infof(ctx, "Attempt to see following from logged out user")
		http.Error(res, "You must be logged in", http.StatusForbidden)
		return
	}
	var sd SessionData
	if err == nil {
		// logged in
		json.Unmarshal(memItem.Value, &sd)
		sd.LoggedIn = true
	}
	// declare a variable of type user
	// initialize user with values from memcache item
	var user User
	json.Unmarshal(memItem.Value, &user)
	// Get followees
	// get the datastore key for the follower
	followerKey := datastore.NewKey(ctx, "Users", user.UserName, 0, nil)
	var XF []F
	_, err = datastore.NewQuery("Follows").Ancestor(followerKey).Project("Following").GetAll(ctx, &XF)
	log.Errorf(ctx, "here is type %T \n and value %v", XF, XF)
	if err != nil {
		log.Errorf(ctx, "error getting followees: %v", err)
		http.Error(res, err.Error(), 500)
		return
	}
	sd.Following = XF
	tpl.ExecuteTemplate(res, "follow.html", &sd)
}
开发者ID:RaviTezu,项目名称:GolangTraining,代码行数:33,代码来源:main.go


示例10: handleCron

func handleCron(w http.ResponseWriter, r *http.Request) *appError {
	// X-Appengine-Cron: true
	c := appengine.NewContext(r)
	a, err := LoadMagazines(c)
	if err != nil {
		return &appError{
			Error:   err,
			Message: "failed to load",
			Code:    http.StatusInternalServerError,
		}
	}
	client := urlfetch.Client(c)
	for _, m := range a {
		f, err := fetchFeed(client, m.URL)
		if err != nil {
			log.Errorf(c, "fetch url: %v", err)
			continue
		}
		if err = SendArticles(c, m, f); err != nil {
			log.Errorf(c, "send article: %v", err)
			continue
		}
	}
	return nil
}
开发者ID:lufia,项目名称:magazine,代码行数:25,代码来源:main.go


示例11: textMessageHandler

func textMessageHandler(w http.ResponseWriter, r *http.Request) {

	ctx := appengine.NewContext(r)

	to := r.FormValue("to")
	text := r.FormValue("text")

	log.Debugf(ctx, "to: %s, text: %s.", to, text)

	chi, _ := strconv.ParseInt(os.Getenv("CHANNEL_ID"), 10, 64)
	chs := os.Getenv("CHANNEL_SECRET")
	mid := os.Getenv("MID")

	client := urlfetch.Client(ctx)
	bot, err := linebot.NewClient(chi, chs, mid, linebot.WithHTTPClient(client))
	if err != nil {
		log.Errorf(ctx, "Client initialization failure. to: %s, text: %s, context: %s", to, text, err.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	res, err := bot.SendText([]string{to}, text)
	if err != nil {
		log.Errorf(ctx, "Message Send Failed. to: %s, text: %s, context: %s", to, text, err.Error())
		w.WriteHeader(http.StatusInternalServerError)
		return
	}
	log.Infof(ctx, "Message send succeed. MessageID: %s, to: %s, text: %s", res.MessageID, to, text)
	w.WriteHeader(http.StatusOK)
}
开发者ID:tksmaru,项目名称:line-gae-echo-bot,代码行数:29,代码来源:app.go


示例12: makeCookie

func makeCookie(m model, req *http.Request) (*http.Cookie, error) {
	ctx := appengine.NewContext(req)

	// DATASTORE
	err := storeDstore(m, req)
	if err != nil {
		log.Errorf(ctx, "ERROR makeCookie storeDstore: %s", err)
		return nil, err
	}

	// MEMCACHE
	err = storeMemc(m, req)
	if err != nil {
		log.Errorf(ctx, "ERROR makeCookie storeMemc: %s", err)
		return nil, err
	}

	// COOKIE
	cookie := &http.Cookie{
		Name:  "session-id",
		Value: m.ID,
		// Secure: true,
		HttpOnly: true,
	}
	return cookie, nil
}
开发者ID:GoesToEleven,项目名称:golang-web,代码行数:26,代码来源:scookie.go


示例13: copyFile

//function copyFile takes in the string fileName and reads that
//fileName in the system then writes it in the gcs in short makes
//a copy of the file to gcs
func (a *app) copyFile(fileName string) {
	writer := a.bucket.Object(fileName).NewWriter(a.ctx)
	writer.ACL = []storage.ACLRule{
		{storage.AllUsers, storage.RoleReader},
	}
	writer.ContentType = "image/jpg"

	//read file from folders img and photos
	b, err := ioutil.ReadFile(fileName)
	if err != nil {
		log.Errorf(a.ctx, "Error in copyFile: ", err)
		return
	}

	//writes the read bytes to gcs bucket.
	_, err = writer.Write(b)
	if err != nil {
		log.Errorf(a.ctx, "createFile: unable to write data to bucket")
		return
	}
	err = writer.Close()
	if err != nil {
		log.Errorf(a.ctx, "createFile Close")
		return
	}
}
开发者ID:jgtaruc,项目名称:GoLang130,代码行数:29,代码来源:main.go


示例14: statFiles

func (d *demo) statFiles() {
	io.WriteString(d.res, "\nRETRIEVING FILE STATS\n")

	client, err := storage.NewClient(d.ctx)
	if err != nil {
		log.Errorf(d.ctx, "%v", err)
		return
	}
	defer client.Close()

	// create a query
	q := storage.Query{
		MaxResults: 2,
	}

	// instead of nil
	// now passing in a *storage.Query
	objs, err := client.Bucket(gcsBucket).List(d.ctx, &q)
	if err != nil {
		log.Errorf(d.ctx, "%v", err)
		return
	}

	for _, v := range objs.Results {
		d.statFile(v.Name)
	}
}
开发者ID:Adrian651,项目名称:CSCI-130-,代码行数:27,代码来源:main.go


示例15: PrimaryPublicCertificates

// PrimaryPublicCertificates returns primary's PublicCertificates.
func PrimaryPublicCertificates(c context.Context, primaryURL string) (*PublicCertificates, error) {
	cacheKey := fmt.Sprintf("pub_certs:%s", primaryURL)
	var pubCerts []byte
	setCache := false
	item, err := memcache.Get(c, cacheKey)
	if err != nil {
		setCache = true
		if err != memcache.ErrCacheMiss {
			log.Warningf(c, "failed to get cert from cache: %v", err)
		}
		pubCerts, err = downloadCert(urlfetch.Client(c), primaryURL)
		if err != nil {
			log.Errorf(c, "failed to download cert: %v", err)
			return nil, err
		}
	} else {
		pubCerts = item.Value
	}
	pc := &PublicCertificates{}
	if err = json.Unmarshal(pubCerts, pc); err != nil {
		log.Errorf(c, "failed to unmarshal cert: %v %v", string(pubCerts), err)
		return nil, err
	}
	if setCache {
		err = memcache.Set(c, &memcache.Item{
			Key:        cacheKey,
			Value:      pubCerts,
			Expiration: time.Hour,
		})
		if err != nil {
			log.Warningf(c, "failed to set cert to cache: %v", err)
		}
	}
	return pc, nil
}
开发者ID:shishkander,项目名称:luci-go,代码行数:36,代码来源:publiccert_appengine.go


示例16: index

func index(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)

	id, err := getID(res, req)
	if err != nil {
		log.Errorf(ctx, "ERROR index getID: %s", err)
		http.Error(res, err.Error(), http.StatusInternalServerError)
		return
	}

	// DATASTORE
	m := model{
		Fname: "Todd",
	}
	err = storeDstore(m, id, req)
	if err != nil {
		log.Errorf(ctx, "ERROR index storeDstore: %s", err)
		http.Error(res, err.Error(), http.StatusInternalServerError)
		return
	}

	// MEMCACHE
	err = storeMemc(m, id, req)
	if err != nil {
		log.Errorf(ctx, "ERROR index storeMemc: %s", err)
		http.Error(res, err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Fprint(res, `
	<h1>EVERYTHING SET ID: `+id+`</h1>
	<h1><a href="/?id=`+id+`">HOME AGAIN</a></h1>
	<h1><a href="/retrieve?id=`+id+`">RETRIEVE</a></h1>
	`)
}
开发者ID:GoesToEleven,项目名称:golang-web,代码行数:35,代码来源:main.go


示例17: New

// New creates a new appengine datastore filesystem.
// Notice that variadic options are submitted as functions,
// as is explained and justified here:
// http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
func New(options ...func(fsi.FileSystem)) *dsFileSys {

	fs := dsFileSys{}

	fs.dirsorter = func(fis []os.FileInfo) { sort.Sort(FileInfoByName(fis)) }
	fs.filesorter = func(fis []DsFile) { sort.Sort(DsFileByName(fis)) }

	for _, option := range options {
		option(&fs)
	}

	if fs.mount == "" {
		fs.mount = MountPointLast()
	}

	if fs.c == nil {
		panic("this type of filesystem needs appengine context, submitted as option")
	}

	rt, err := fs.dirByPath(fs.mount)
	_ = rt
	if err == datastore.ErrNoSuchEntity {
		rt, err = fs.saveDirByPath(fs.mount) // fine
		if err != nil {
			aelog.Errorf(fs.c, "could not create mount %v => %v", fs.mount, err)
		} else {
		}
	} else if err != nil {
		aelog.Errorf(fs.c, "could read mount dir %v => %v", fs.mount, err)
	} else {
		// fs.Ctx().Infof("Found rtdr %v  %v  %v ", rt.Dir, rt.BName, rt.Key)
	}

	return &fs
}
开发者ID:aarzilli,项目名称:tools,代码行数:39,代码来源:21_fs_new.go


示例18: handle

func handle(res http.ResponseWriter, req *http.Request) {
	if req.URL.Path != "/" {
		http.NotFound(res, req)
		return
	}
	ctx := appengine.NewContext(req)
	u := user.Current(ctx)
	key := datastore.NewKey(ctx, "Profile", u.Email, 0, nil)
	var profile Profile
	err := datastore.Get(ctx, key, &profile)
	if err == datastore.ErrNoSuchEntity {
		http.Redirect(res, req, "/createProfile", http.StatusSeeOther)
		return
	} else if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Errorf(ctx, err.Error())
		return
	}

	tpl, err := template.ParseFiles("viewProfile.gohtml")
	if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Errorf(ctx, err.Error())
		return
	}
	err = tpl.Execute(res, &profile)
	if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Errorf(ctx, err.Error())
		return
	}
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:32,代码来源:main.go


示例19: batchSingleFlightHandler

// To run a job directly: /backend/fdb-batch/flight?job=...&key=...&
func batchSingleFlightHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	f, err := formValueFlightByKey(r)
	if err != nil {
		log.Errorf(c, "batch/fdb/track/getflight: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	// You now have a job name, and a flight object. Get to it !
	job := r.FormValue("job")
	var str string = ""
	switch job {
	case "tracktimezone":
		str, err = jobTrackTimezoneHandler(r, f)
	case "oceanictag":
		str, err = jobOceanicTagHandler(r, f)
	case "v2adsb":
		str, err = jobV2adsbHandler(r, f)
	}

	if err != nil {
		log.Errorf(c, "%s", str)
		log.Errorf(c, "backend/fdb-batch/flight: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	log.Debugf(c, "job=%s, on %s: %s", job, f, str)

	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte(fmt.Sprintf("OK\n * %s\n%s\n", f, str)))
}
开发者ID:hugoh,项目名称:complaints,代码行数:35,代码来源:flight-batch.go


示例20: createProfile

func createProfile(res http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	if req.Method == "POST" {
		u := user.Current(ctx)
		profile := Profile{
			Email:     u.Email,
			FirstName: req.FormValue("firstname"),
			LastName:  req.FormValue("lastname"),
		}
		key := datastore.NewKey(ctx, "Profile", u.Email, 0, nil)
		_, err := datastore.Put(ctx, key, &profile)
		if err != nil {
			http.Error(res, "Server Error", http.StatusInternalServerError)
			log.Errorf(ctx, err.Error())
			return
		}
		http.Redirect(res, req, "/", http.StatusSeeOther)
	}
	f, err := os.Open("createProfile.gohtml")
	if err != nil {
		http.Error(res, "Server Error", http.StatusInternalServerError)
		log.Errorf(ctx, err.Error())
		return
	}
	io.Copy(res, f)
}
开发者ID:CodingDance,项目名称:GolangTraining,代码行数:26,代码来源:main.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Infof函数代码示例发布时间:2022-05-28
下一篇:
Golang log.Debugf函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap