miscellaneous.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package apiv1
  5. import (
  6. "reflect"
  7. "github.com/Unknwon/macaron"
  8. "github.com/macaron-contrib/binding"
  9. "github.com/gogits/gogs/modules/auth"
  10. )
  11. type MarkdownForm struct {
  12. Text string `form:"text"`
  13. Mode string `form:"mode"`
  14. Context string `form:"context"`
  15. }
  16. func (f *MarkdownForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  17. return validateApiReq(errs, ctx.Data, f)
  18. }
  19. func validateApiReq(errs binding.Errors, data map[string]interface{}, f auth.Form) binding.Errors {
  20. if errs.Len() == 0 {
  21. return errs
  22. }
  23. data["HasError"] = true
  24. typ := reflect.TypeOf(f)
  25. val := reflect.ValueOf(f)
  26. if typ.Kind() == reflect.Ptr {
  27. typ = typ.Elem()
  28. val = val.Elem()
  29. }
  30. for i := 0; i < typ.NumField(); i++ {
  31. field := typ.Field(i)
  32. fieldName := field.Tag.Get("form")
  33. // Allow ignored fields in the struct
  34. if fieldName == "-" {
  35. continue
  36. }
  37. if errs[0].FieldNames[0] == field.Name {
  38. switch errs[0].Classification {
  39. case binding.ERR_REQUIRED:
  40. data["ErrorMsg"] = fieldName + " cannot be empty"
  41. case binding.ERR_ALPHA_DASH:
  42. data["ErrorMsg"] = fieldName + " must be valid alpha or numeric or dash(-_) characters"
  43. case binding.ERR_ALPHA_DASH_DOT:
  44. data["ErrorMsg"] = fieldName + " must be valid alpha or numeric or dash(-_) or dot characters"
  45. case binding.ERR_MIN_SIZE:
  46. data["ErrorMsg"] = fieldName + " must contain at least " + auth.GetMinSize(field) + " characters"
  47. case binding.ERR_MAX_SIZE:
  48. data["ErrorMsg"] = fieldName + " must contain at most " + auth.GetMaxSize(field) + " characters"
  49. case binding.ERR_EMAIL:
  50. data["ErrorMsg"] = fieldName + " is not a valid e-mail address"
  51. case binding.ERR_URL:
  52. data["ErrorMsg"] = fieldName + " is not a valid URL"
  53. default:
  54. data["ErrorMsg"] = "Unknown error: " + errs[0].Classification
  55. }
  56. return errs
  57. }
  58. }
  59. return errs
  60. }
PANIC: session(release): write data/sessions/5/f/5f2efd8209a731a8: no space left on device

PANIC

session(release): write data/sessions/5/f/5f2efd8209a731a8: no space left on device
github.com/go-macaron/session@v0.0.0-20190805070824-1a3cdc6f5659/session.go:199 (0x8b2934)
gopkg.in/macaron.v1@v1.3.9/context.go:79 (0x83d0a0)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/context.go:112 (0x84fdb5)
gopkg.in/macaron.v1@v1.3.9/recovery.go:161 (0x84fda8)
gopkg.in/macaron.v1@v1.3.9/logger.go:40 (0x840c73)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:157 (0x80ab07)
github.com/go-macaron/inject@v0.0.0-20160627170012-d8a0b8677191/inject.go:135 (0x80a8a8)
gopkg.in/macaron.v1@v1.3.9/context.go:121 (0x83d1f8)
gopkg.in/macaron.v1@v1.3.9/router.go:187 (0x850fc6)
gopkg.in/macaron.v1@v1.3.9/router.go:303 (0x8493e5)
gopkg.in/macaron.v1@v1.3.9/macaron.go:220 (0x841fca)
net/http/server.go:2836 (0x7a79b2)
net/http/server.go:1924 (0x7a341b)
runtime/asm_amd64.s:1373 (0x46f9f0)