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


Golang common.CheckError函數代碼示例

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


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


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