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

Golang common.CheckError函数代码示例

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

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



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

示例1: saveBandRecordToConcertHandler

func saveBandRecordToConcertHandler(rw http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	common.CheckError(err)
	form := req.Form

	concertId, err := strconv.ParseInt(form["concert_id"][0], 10, 64)
	common.CheckError(err)

	bandId, err := strconv.ParseInt(form["band_id"][0], 10, 64)

	dbmap := db.InitDb(BandConcert{}, "band_concert")
	defer dbmap.Db.Close()

	bandConcert := BandConcert{BandId: bandId, ConcertId: concertId}
	err = dbmap.SelectOne(&bandConcert, "SELECT * FROM concertsap.concert_band WHERE band_id=? AND concert_id=?", bandConcert.BandId, bandConcert.ConcertId)

	if err != nil {
		insertBandConcert(bandConcert)
		err = dbmap.SelectOne(&bandConcert, "SELECT * FROM concertsap.concert_band WHERE band_id=? AND concert_id=?", bandConcert.BandId, bandConcert.ConcertId)
	}

	formDate := form["date"][0]
	formTime := form["time"][0]
	bandConcertRecord := BandConcertRecord{BandId: bandConcert.BandId, ConcertId: bandConcert.ConcertId, Date: formDate, Time: formTime}
	insertBandConcertRecord(bandConcertRecord)

	http.Redirect(rw, req, "addBandRecordToConcert", http.StatusFound)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:28,代码来源:adminController.go


示例2: addHandler

func addHandler(rw http.ResponseWriter, req *http.Request) {
	if req.Method == "POST" {
		dbmap := db.InitDb(Retailer{}, "retailer")
		defer dbmap.Db.Close()

		err := req.ParseForm()
		common.CheckError(err)
		form := req.Form

		err = dbmap.Insert(&Retailer{Name: form["name"][0], Website: form["website"][0]})
		common.CheckError(err)
	}

	type Page struct {
		PageName string
		Title    string
	}

	p := Page{
		PageName: "retailer",
		Title:    "Add Controller",
	}

	common.Templates = template.Must(template.ParseFiles("templates/retailer/add.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:27,代码来源:controller.go


示例3: saveBandsToConcertHandler

func saveBandsToConcertHandler(rw http.ResponseWriter, req *http.Request) {
	dbmap := db.InitDb(Band{}, "band")
	defer dbmap.Db.Close()

	err := req.ParseForm()
	common.CheckError(err)
	form := req.Form

	concertId, err := strconv.ParseInt(form["concert_id"][0], 10, 64)
	common.CheckError(err)

	r, err := regexp.Compile(`([^<]+)<br>`)
	common.CheckError(err)
	rawBands := form["parsedInput"][0]
	bandMatches := r.FindAllStringSubmatch(rawBands, -1)

	for _, bandName := range bandMatches {
		newBand := Band{Name: bandName[1]}
		err = dbmap.SelectOne(&newBand, "SELECT * FROM concertsap.band WHERE name=?", strings.ToUpper(newBand.Name))

		if err != nil {
			insertBand(newBand)
			err = dbmap.SelectOne(&newBand, "SELECT * FROM concertsap.band WHERE name=?", newBand.Name)
		}

		newBandConcert := BandConcert{BandId: newBand.Id, ConcertId: concertId}
		insertBandConcert(newBandConcert)
	}

	http.Redirect(rw, req, "addBandsToConcert", http.StatusFound)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:31,代码来源:adminController.go


示例4: userViewOneHandler

func userViewOneHandler(rw http.ResponseWriter, req *http.Request) {
	params := mux.Vars(req)
	id := params["id"]

	type Page struct {
		PageName     string
		Title        string
		Concert      Concert
		ConcertState int
		UntilDays    int
	}

	concert := FindOne(id)

	var concertState int
	var untilDays int

	tStart, terr := time.Parse("2006-01-02 15:04:05", concert.Start+" 23:59:59")
	common.CheckError(terr)

	tEnd, terr := time.Parse("2006-01-02 15:04:05", concert.End+" 23:59:59")
	common.CheckError(terr)

	if time.Now().After(tEnd) {
		// Concert is in the past - concertState = 1
		concertState = 1
		untilDays = int(time.Since(tEnd).Hours()/24) + 1
	} else if time.Now().After(tStart) {
		// Concert is now! - concertState = 2
		concertState = 2
		untilDays = int(time.Since(tEnd).Hours()/24) + 1
	} else {
		// Concert is in the future - concertState = 3
		concertState = 3
		untilDays = -1*int(time.Since(tStart).Hours()/24) + 1
	}

	p := Page{
		PageName:     "user_concert",
		Title:        "View One Controller: " + id,
		Concert:      concert,
		ConcertState: concertState,
		UntilDays:    untilDays,
	}

	common.Templates = template.Must(template.ParseFiles("templates/concert/userViewOne.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:49,代码来源:userController.go


示例5: addHandler

func addHandler(rw http.ResponseWriter, req *http.Request) {
	type Page struct {
		PageName  string
		Title     string
		Concerts  []concert.Concert
		Retailers []retailer.Retailer
		Now       string
	}

	concerts := concert.FindAll()
	retailers := retailer.FindAll()
	t := time.Now()

	p := Page{
		PageName:  "ticket",
		Title:     "Add Controller",
		Concerts:  concerts,
		Retailers: retailers,
		Now:       t.Format("2006-01-02 15:04:05"),
	}

	common.Templates = template.Must(template.ParseFiles("templates/ticket/add.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:25,代码来源:adminController.go


示例6: FindBandConcert

func FindBandConcert(concertId string) []BandJoinedConcert {
	dbmap := db.InitDb(BandConcert{}, "band_concert")
	defer dbmap.Db.Close()

	var concertIdString string

	if concertId != "" {
		concertIdString = "AND c.id = " + concertId
	}

	var bandConcerts []BandJoinedConcert
	_, err := dbmap.Select(&bandConcerts, `
        SELECT b.id AS band_id,
            b.name AS band_name,
            b.website AS band_website,
            c.id AS concert_id,
            c.name AS concert_name,
            c.address AS concert_address,
            c.state_id AS concert_state_id,
            c.website AS concert_website,
            c.start AS concert_start,
            c.end AS concert_end
        FROM band_concert bc
        JOIN band b
        ON b.id = bc.band_id
        JOIN concert c
        ON c.id = bc.concert_id
        `+concertIdString+`
        ORDER BY b.name`)
	common.CheckError(err)

	return bandConcerts
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:33,代码来源:bandConcertModel.go


示例7: ConcertBandHandler

func ConcertBandHandler(rw http.ResponseWriter, req *http.Request) {
	params := mux.Vars(req)
	id := params["id"]

	json, err := json.Marshal(band.FindBandConcert(id))
	common.CheckError(err)

	fmt.Fprintf(rw, "%v", string(json))
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:9,代码来源:concert.go


示例8: FindOne

func FindOne(id string) Concert {
	dbmap := db.InitDb(Concert{}, "concert")
	defer dbmap.Db.Close()

	var concert Concert
	err := dbmap.SelectOne(&concert, "SELECT * FROM concert WHERE id = ? ORDER BY name", id)
	common.CheckError(err)

	return concert
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:10,代码来源:model.go


示例9: FindAll

func FindAll() []Concert {
	dbmap := db.InitDb(Concert{}, "concert")
	defer dbmap.Db.Close()

	var concerts []Concert
	_, err := dbmap.Select(&concerts, "SELECT * FROM concert ORDER BY name")
	common.CheckError(err)

	return concerts
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:10,代码来源:model.go


示例10: FindOne

func FindOne(id string) Band {
	dbmap := db.InitDb(Band{}, "band")
	defer dbmap.Db.Close()

	var band Band
	err := dbmap.SelectOne(&band, "SELECT * FROM band WHERE id = ? ORDER BY name", id)
	common.CheckError(err)

	return band
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:10,代码来源:bandModel.go


示例11: FindBandsAndConcerts

func FindBandsAndConcerts() []BandAndConcertsCount {
	dbmap := db.InitDb(Band{}, "band")
	defer dbmap.Db.Close()

	var bandsAndConcertsCount []BandAndConcertsCount
	_, err := dbmap.Select(&bandsAndConcertsCount, "SELECT b.id, b.name, COUNT(*) AS count_count FROM band_concert bc JOIN band b ON bc.band_id = b.id GROUP BY b.id ORDER BY b.name")
	common.CheckError(err)

	return bandsAndConcertsCount
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:10,代码来源:bandModel.go


示例12: FindAll

func FindAll() []Band {
	dbmap := db.InitDb(Band{}, "band")
	defer dbmap.Db.Close()

	var bands []Band
	_, err := dbmap.Select(&bands, "SELECT * FROM band ORDER BY name")
	common.CheckError(err)

	return bands
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:10,代码来源:bandModel.go


示例13: saveHandler

func saveHandler(rw http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	common.CheckError(err)
	form := req.Form

	stateId, err := strconv.ParseInt(common.IssetInForm(form["state_id"], 0), 10, 64)
	common.CheckError(err)

	concert := Concert{
		Name:    common.IssetInForm(form["name"], 0),
		Address: common.IssetInForm(form["address"], 0),
		StateId: stateId,
		Website: common.IssetInForm(form["website"], 0),
		Start:   common.IssetInForm(form["start"], 0),
		End:     common.IssetInForm(form["end"], 0),
	}

	insertConcert(concert)

	http.Redirect(rw, req, "add", http.StatusFound)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:21,代码来源:adminController.go


示例14: InitDb

func InitDb(i interface{}, dbName string) *gorp.DbMap {
	// connect to db using standard Go database/sql API
	// use whatever database/sql driver you wish
	db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/concertsap")
	common.CheckError(err)

	// construct a gorp DbMap
	dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{}}

	dbmap.AddTableWithName(i, dbName).SetKeys(true, "id")

	return dbmap
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:13,代码来源:database.go


示例15: saveHandler

func saveHandler(rw http.ResponseWriter, req *http.Request) {
	err := req.ParseForm()
	common.CheckError(err)
	form := req.Form

	retailer := Retailer{
		Name:    common.IssetInForm(form["name"], 0),
		Website: common.IssetInForm(form["website"], 0),
	}

	insertRetailer(retailer)

	http.Redirect(rw, req, "add", http.StatusFound)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:14,代码来源:controller.go


示例16: loginHandler

func loginHandler(rw http.ResponseWriter, req *http.Request) {
	type Page struct {
		PageName string
		Title    string
	}

	p := Page{
		PageName: "login",
		Title:    "Login",
	}

	common.Templates = template.Must(template.ParseFiles("templates/home/login.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:15,代码来源:login.go


示例17: FindConcertsByBand

func FindConcertsByBand(bandId string) []Concert {
	dbmap := db.InitDb(Concert{}, "concert")
	defer dbmap.Db.Close()

	var concerts []Concert
	_, err := dbmap.Select(&concerts, `
        SELECT c.*
        FROM band_concert bc
        JOIN concert c
        ON c.id = bc.concert_id
        WHERE bc.band_id = ?
        ORDER BY name`, bandId)
	common.CheckError(err)

	return concerts
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:16,代码来源:model.go


示例18: adminViewOneHandler

func adminViewOneHandler(rw http.ResponseWriter, req *http.Request) {
	params := mux.Vars(req)
	id := params["id"]

	type Page struct {
		PageName string
		Title    string
	}

	p := Page{
		PageName: "admin_concert",
		Title:    "View One Controller: " + id,
	}

	common.Templates = template.Must(template.ParseFiles("templates/concert/adminViewOne.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:18,代码来源:adminController.go


示例19: editHandler

func editHandler(rw http.ResponseWriter, req *http.Request) {
	params := mux.Vars(req)
	id := params["id"]

	type Page struct {
		PageName string
		Title    string
	}

	p := Page{
		PageName: "retailer",
		Title:    "Edit Controller: " + id,
	}

	common.Templates = template.Must(template.ParseFiles("templates/retailer/edit.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:18,代码来源:controller.go


示例20: adminViewAllHandler

func adminViewAllHandler(rw http.ResponseWriter, req *http.Request) {
	type Page struct {
		PageName string
		Title    string
		Concerts []Concert
	}

	concerts := FindAll()

	p := Page{
		PageName: "admin_concert",
		Title:    "View All Concerts",
		Concerts: concerts,
	}

	common.Templates = template.Must(template.ParseFiles("templates/concert/adminViewAll.html", common.LayoutPath))
	err := common.Templates.ExecuteTemplate(rw, "base", p)
	common.CheckError(err)
}
开发者ID:jadekler,项目名称:git-go-d3-concertsap,代码行数:19,代码来源:adminController.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang clownfish.CFStringToGo函数代码示例发布时间:2022-05-24
下一篇:
Golang gform.EventArg类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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