本文整理汇总了Golang中github.com/peteraba/go-blah/template.Messages类的典型用法代码示例。如果您正苦于以下问题:Golang Messages类的具体用法?Golang Messages怎么用?Golang Messages使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Messages类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DeleteLatestNews
func DeleteLatestNews(ren render.Render, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
_, err := repository.DeleteLatestNews(db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete news.")
} else {
sessionMessages.AddSuccess("Successfully deleted news.")
}
ren.Redirect("/latest_news")
}
示例2: UpdatePlant
func UpdatePlant(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
id, _ := strconv.ParseInt(params["id"], 10, 64)
plant := entity.NewPlant()
plant.Populate(getPlantMap(r, params["id"]))
val, errors := validation.ValidateDefaultEntity(plant, db, PLANT)
if val {
_, err := repository.UpdatePlant(plant, db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to update plant.")
} else {
sessionMessages.AddSuccess("Successfully update plant.")
updatePopularNames(db, id, PLANT, plant.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, PLANT, id)
}
ren.Redirect("/plant/")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/plant/" + params["id"])
}
}
示例3: CreatePlant
func CreatePlant(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
plant := entity.NewPlant()
plant.Populate(getPlantMap(r, ""))
val, errors := validation.ValidateDefaultEntity(plant, db, PLANT)
if val {
res, err := repository.InsertPlant(plant, db)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to create plant.")
} else {
sessionMessages.AddSuccess("Successfully created plant.")
id, _ := res.LastInsertId()
insertPopularNames(db, id, PLANT, plant.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, PLANT, id)
}
ren.Redirect("/plant")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/plant/new")
}
}
示例4: UpdateComponent
func UpdateComponent(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
id, _ := strconv.ParseInt(params["id"], 10, 64)
component := entity.NewComponent()
component.Populate(getComponentMap(r, params["id"]))
val, errors := validation.ValidateComponent(component, db, COMPONENT)
if val {
_, err := repository.UpdateComponent(component, db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to update component.")
} else {
sessionMessages.AddSuccess("Successfully updated component.")
createMedia(r, mediaManager, db, sessionMessages, COMPONENT, id)
}
ren.Redirect("/component")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/component/" + params["id"])
}
}
示例5: CreateComponent
func CreateComponent(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
component := entity.NewComponent()
component.Populate(getComponentMap(r, ""))
val, errors := validation.ValidateComponent(component, db, COMPONENT)
if val {
res, err := repository.InsertComponent(component, db)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to create component.")
} else {
sessionMessages.AddSuccess("Successfully created component.")
id, _ := res.LastInsertId()
createMedia(r, mediaManager, db, sessionMessages, "component", id)
}
ren.Redirect("/component")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/component/new")
}
}
示例6: DeleteComponent
func DeleteComponent(ren render.Render, mediaManager *media.Manager, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
var err error
id, _ := strconv.ParseInt(params["id"], 10, 64)
media_list := getMediaList(db, COMPONENT, id)
if media_list != nil {
_, errors := DeleteEntityMedia(*media_list, mediaManager, db)
for _, err := range errors {
log.Println(err)
}
_, err = repository.DeleteEntityMedia(db, id, COMPONENT)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete media for component.")
}
}
_, err = repository.DeleteComponent(db, id)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete component.")
} else {
sessionMessages.AddSuccess("Successfully deleted component.")
}
ren.Redirect("/component")
}
示例7: Upload
func (m *Manager) Upload(r *http.Request, sessionMessages *template.Messages, args ...string) map[int]string {
filenames := make(map[int]string)
for key, form_key := range args {
if !m.hasUpload(r, form_key) {
//sessionMessages.AddInfo(fmt.Sprintf("No file upload for upload field #%d", key+1))
continue
}
file, header, err := r.FormFile(form_key)
if err != nil {
sessionMessages.AddDanger(fmt.Sprintf(err.Error()))
}
data, err := ioutil.ReadAll(file)
if err != nil {
sessionMessages.AddDanger(fmt.Sprintf("Couldn't read uploaded file. #%d", key+1))
continue
}
content_type := header.Header.Get("Content-Type")
filename := m.getFileName(data)
extension := m.getExtensionName(content_type)
for _, uploadHandler := range m.uploadHandlers {
go uploadHandler.Upload(data, filename, extension, content_type)
}
filenames[key] = filename + "." + extension
sessionMessages.AddSuccess(fmt.Sprintf("File is being uploaded for upload field #%d", key+1))
}
return filenames
}
示例8: UpdateLatestNews
func UpdateLatestNews(ren render.Render, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
latest_news := entity.NewLatestNews()
latest_news.Populate(getLatestNewsMap(r))
val, errors := validation.ValidateLatestNews(latest_news, db, LATEST_NEWS)
if val {
_, err := repository.UpdateLatestNews(latest_news, db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to upload news.")
} else {
sessionMessages.AddSuccess("Successfully upload news.")
}
ren.Redirect("/latest_news")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/latest_news/" + params["id"])
}
}
示例9: UpdateInvertebrate
func UpdateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
id, _ := strconv.ParseInt(params["id"], 10, 64)
invertebrate := entity.NewInvertebrate()
invertebrate.Populate(getInvertebrateMap(r, params["id"]))
val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE)
if val {
_, err := repository.UpdateInvertebrate(invertebrate, db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to upload invertebrate.")
} else {
sessionMessages.AddSuccess("Successfully upload invertebrate.")
updatePopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id)
}
ren.Redirect("/invertebrate")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/invertebrate/" + params["id"])
}
}
示例10: CreateInvertebrate
func CreateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
invertebrate := entity.NewInvertebrate()
invertebrate.Populate(getInvertebrateMap(r, ""))
val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE)
if val {
res, err := repository.InsertInvertebrate(invertebrate, db)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to create invertebrate.")
} else {
sessionMessages.AddSuccess("Successfully created invertebrate.")
id, _ := res.LastInsertId()
insertPopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id)
}
ren.Redirect("/invertebrate")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/invertebrate/new")
}
}
示例11: UpdateCoral
func UpdateCoral(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
id, _ := strconv.ParseInt(params["id"], 10, 64)
coral := entity.NewCoral()
coral.Populate(getCoralMap(r, params["id"]))
val, errors := validation.ValidateCoral(coral, db, CORAL)
if val {
_, err := repository.UpdateCoral(coral, db, params["id"])
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to update coral.")
} else {
sessionMessages.AddSuccess("Successfully update coral.")
updatePopularNames(db, id, CORAL, coral.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, CORAL, id)
}
ren.Redirect("/coral")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/coral/" + params["id"])
}
}
示例12: CreateCoral
func CreateCoral(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
coral := entity.NewCoral()
coral.Populate(getCoralMap(r, ""))
val, errors := validation.ValidateCoral(coral, db, CORAL)
if val {
res, err := repository.InsertCoral(coral, db)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to create coral.")
} else {
sessionMessages.AddSuccess("Successfully created coral.")
id, _ := res.LastInsertId()
insertPopularNames(db, id, CORAL, coral.GetPopularNames().GetValues())
createMedia(r, mediaManager, db, sessionMessages, CORAL, id)
}
ren.Redirect("/coral")
} else {
for k, msg := range errors {
sessionMessages.AddDanger(k + ": " + msg)
}
ren.Redirect("/coral/new")
}
}
示例13: DeleteInvertebrate
func DeleteInvertebrate(ren render.Render, mediaManager *media.Manager, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
var err error
id, _ := strconv.ParseInt(params["id"], 10, 64)
media_list := getMediaList(db, INVERTEBRATE, id)
if media_list != nil {
_, errors := DeleteEntityMedia(*media_list, mediaManager, db)
for _, err := range errors {
log.Println(err)
}
_, err = repository.DeleteEntityMedia(db, id, INVERTEBRATE)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete media for invertebrate.")
}
}
_, err = repository.DeleteEntityNames(db, id, INVERTEBRATE)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete popular names for invertabrate.")
}
_, err = repository.DeleteInvertebrate(db, id)
if err != nil {
log.Println(err)
sessionMessages.AddDanger("Failed to delete invertebrate.")
} else {
sessionMessages.AddSuccess("Successfully deleted invertebrate.")
}
ren.Redirect("/invertebrate")
}