它的文档记录不是很好,但是显然从会话中
Flashes删除了 闪烁并返回了它们:
func (s *Session) Flashes(vars ...string) []interface{} { var flashes []interface{} key := flashesKey if len(vars) > 0 { key = vars[0] } if v, ok := s.Values[key]; ok { // Drop the flashes and return it. delete(s.Values, key) flashes = v.([]interface{}) } return flashes}源代码在这里。
这里的解决方案是使用一个单独的变量来保存验证状态:
valid := trueif username == "" || len(username) < 4 { valid = false session.AddFlash("Username is too short") session.Save(r, w)}// ...if !valid { // ...} else { // ...}编辑: 获取闪光灯而不删除它们的另一种方法是
Values直接从其中获取它们:
flashes := session.Values["_flash"].([]interface{})


