summaryrefslogtreecommitdiff
path: root/formdec.go
diff options
context:
space:
mode:
Diffstat (limited to 'formdec.go')
-rw-r--r--formdec.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/formdec.go b/formdec.go
new file mode 100644
index 0000000..d554696
--- /dev/null
+++ b/formdec.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "github.com/gorilla/schema"
+ "reflect"
+ "regexp"
+ "time"
+)
+
+type EMail string
+
+var emailRegex = regexp.MustCompile(`^.+@.+$`)
+
+func EMailConvert(s string) reflect.Value {
+ if emailRegex.MatchString(s) {
+ return reflect.ValueOf(EMail(s))
+ }
+ return reflect.Value{}
+}
+
+type timelocForm struct {
+ Loc *time.Location
+}
+
+func locationConverter(s string) reflect.Value {
+ loc, err := time.LoadLocation(s)
+ if err != nil {
+ return reflect.Value{}
+ }
+ return reflect.ValueOf(timelocForm{loc})
+}
+
+var formdec *schema.Decoder
+
+func init() {
+ formdec = schema.NewDecoder()
+ formdec.RegisterConverter(EMail(""), EMailConvert)
+ formdec.RegisterConverter(timelocForm{}, locationConverter)
+}