settings.go (912B)
1 package main 2 3 import ( 4 "net/mail" 5 "errors" 6 7 "github.com/gin-gonic/gin" 8 ) 9 10 type SettingReturn struct { 11 Type string `json:"type"` 12 Default any `json:"default"` 13 Memo string `json:"description"` 14 } 15 16 func (e *Env) GetSettings(c *gin.Context) { 17 r := make(map[string]SettingReturn) 18 s := e.backend.Settings() 19 for k, v := range s { 20 r[k] = SettingReturn{Type: v.Primitive, Memo: v.Memo, Default: v.DefaultValue} 21 } 22 Respond(c, 200, r) 23 } 24 25 func validateEmail(value interface{}) (bool, error) { 26 s, ok := value.(string) 27 if !ok { 28 return false, errors.New("Invalid type") 29 } 30 31 _, err := mail.ParseAddress(s) 32 if err != nil { 33 return false, err 34 } 35 return true, nil 36 } 37 38 func validateEmailPolicy(value any) (bool, error) { 39 s, ok := value.(string) 40 if !ok { 41 return false, errors.New("Invalid type") 42 } 43 44 if s != "strict" { 45 return false, errors.New(s + ": Invalid policy. Must be strict.") 46 } 47 return true, nil 48 }