本文整理匯總了Golang中github.com/goinggo/tracelog.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HomeHandler
func HomeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
brand := vars["brand"]
postalCode := vars["postalCode"]
tracelog.Trace("Brand Value", "main", "Brand is %s", brand)
tracelog.Trace("Postal Code", "main", "PostalCode is %s", postalCode)
// now call the Edmunds API
dealers, dealerErr := DealersAroundZipCode(postalCode, 100, brand, true)
if dealerErr != nil {
ReturnErrorToClient(w, dealerErr, "Error calling dealer service with zip code "+postalCode)
tracelog.Error(dealerErr, "DealersAroundZipCode failed", "HomeHandler")
return
}
w.WriteHeader(http.StatusOK)
var err error
if err = json.NewEncoder(w).Encode(dealers); err != nil {
tracelog.Error(err, "JSON encoding failed", "HomeHandler")
panic(err)
}
}
示例2: ReturnErrorToClient
func ReturnErrorToClient(w http.ResponseWriter, err error, msg string) {
tracelog.Error(err, msg, "ReturnErrorToClient")
w.WriteHeader(http.StatusBadRequest)
if encodeError := json.NewEncoder(w).Encode(JsonError{Code: http.StatusBadRequest, Error: msg}); encodeError != nil {
tracelog.Error(encodeError, "JSON encoding failed", "ReturnErrorToClient")
panic("JSON encoding failed")
}
}
示例3: AddBook
func AddBook(jsonStr []byte) bool {
o := orm.NewOrm()
var book Book
err := json.Unmarshal(jsonStr, &book)
if err != nil {
tracelog.Error(err, "Failed to insert json", "model.AddBook")
return false
}
_, err = o.Insert(&book)
if err != nil {
tracelog.Error(err, "Failed to insert book", "model.AddBook")
return false
}
return true
}
示例4: UpdateLibrary
func UpdateLibrary(jsonStr []byte) bool {
o := orm.NewOrm()
var lib Library
err := json.Unmarshal(jsonStr, &lib)
if err != nil {
tracelog.Error(err, "Failed to parse json", "model.UpdateLibrary")
return false
}
_, err = o.Update(&lib)
if err != nil {
tracelog.Error(err, "Failed to update lib", "model.UpdateLibrary")
return false
}
return true
}
示例5: AddLibrary
func AddLibrary(jsonStr []byte) bool {
o := orm.NewOrm()
var lib Library
err := json.Unmarshal(jsonStr, &lib)
if err != nil {
tracelog.Error(err, "Failed to insert json", "model.AddLibrary")
return false
}
_, err = o.Insert(&lib)
if err != nil {
tracelog.Error(err, "Failed to insert lib", "model.AddLibrary")
return false
}
return true
}
示例6: UpdateBook
func UpdateBook(jsonStr []byte) bool {
o := orm.NewOrm()
var book Book
err := json.Unmarshal(jsonStr, &book)
if err != nil {
tracelog.Error(err, "Failed to parse json", "model.UpdateBook")
return false
}
_, err = o.Update(&book)
if err != nil {
tracelog.Error(err, "Failed to update book", "model.UpdateBook")
return false
}
return true
}
示例7: DeleteLibrary
func DeleteLibrary(libId int64) bool {
o := orm.NewOrm()
if _, err := o.Delete(&Library{Id: libId}); err == nil {
tracelog.Error(err, "Failed to delete lib", "model.DeleteLibrary")
return false
}
return true
}
示例8: DeleteBook
func DeleteBook(bookId int64) bool {
o := orm.NewOrm()
if _, err := o.Delete(&Book{Id: bookId}); err == nil {
tracelog.Error(err, "Failed to query", "model.DeleteBook")
return false
}
return true
}
示例9: Prepare
// Prepare is called before any controller.
func (service *Service) Prepare() (err error) {
service.MongoSession, err = mongo.CopyMonotonicSession(service.UserID)
if err != nil {
log.Error(err, service.UserID, "Service.Prepare")
return err
}
return err
}
示例10: GetBook
func GetBook(bookId int64) (*Book, error) {
o := orm.NewOrm()
book := Book{Id: bookId}
err := o.Read(&book)
if err != nil {
tracelog.Error(err, "Failed to query", "model.GetBook")
}
return &book, err
}
示例11: AddBookInLibrary
func AddBookInLibrary(libraryId int64, bookId int64) bool {
o := orm.NewOrm()
_, err := o.Raw(`
INSERT INTO book_library(book_id, library_id) VALUES(?, ?)`, bookId, libraryId).Exec()
if err != nil {
tracelog.Error(err, "Failed to query", "model.AddBookInLibrary")
return false
}
return true
}
示例12: listBooksInLibrary
func (c *LibraryController) listBooksInLibrary() {
libId, _ := strconv.ParseInt(c.Ctx.Input.Param(":libId"), 10, 64)
books, err := model.GetBooksInLibrary(libId)
if err == orm.ErrNoRows {
tracelog.Error(err, "No result found", "MainController")
}
c.Data["json"] = &books
c.ServeJson()
}
示例13: main
func main() {
tracelog.Start(tracelog.LevelTrace)
//tracelog.Start(tracelog.LevelInfo)
var port = os.Getenv("PORT")
if port == "" {
tracelog.Error(nil, "The PORT environment variable has not been set.", "main")
os.Exit(1)
}
var myGasFeedBaseUrl = os.Getenv("MY_GAS_FEED_BASE_URL")
if myGasFeedBaseUrl == "" {
tracelog.Error(nil, "The MY_GAS_FEED_BASE_URL environment variable has not been set.", "main")
}
SetMyGasFeedBaseUrl(myGasFeedBaseUrl)
var myGasFeedApiKey = os.Getenv("MY_GAS_FEED_API_KEY")
if myGasFeedApiKey == "" {
tracelog.Error(nil, "The MY_GAS_FEED_API_KEY environment variable has not been set.", "main")
}
SetMyGasFeedApiKey(myGasFeedApiKey)
tracelog.Info("Started", "main", "Gas Price Service is starting and listening on port %s", port)
router := mux.NewRouter()
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc
handler = Logger(handler, route.Name)
router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(handler)
}
err := http.ListenAndServe(":"+port, router)
if err != nil {
tracelog.Error(err, "An error occurred while attempting to listen and serve", "main")
}
tracelog.Info("Stopped", "main", "Gas Price Service has been terminated")
tracelog.Stop()
}
示例14: login
func (p *MgoCtx) login(db *mgo.Database) bool {
if p.cfg.Pwd == "" {
return true
}
if err := db.Login(p.cfg.User, p.cfg.Pwd); err != nil {
log.Error(err, "Login", "mdb.Startup")
return false
}
return true
}
示例15: GetAllBooks
func GetAllBooks() (*[]Book, error) {
var rows []Book
o := orm.NewOrm()
_, err := o.Raw(`
SELECT b.id, b.name, b.author
FROM book b`).QueryRows(&rows)
if err != nil {
tracelog.Error(err, "Failed to query", "model.GetAllBooks")
}
return &rows, err
}