68 lines
1.1 KiB
Go
68 lines
1.1 KiB
Go
package web
|
|
|
|
import "encoding/gob"
|
|
|
|
func init() {
|
|
gob.Register(CreatePostForm{})
|
|
gob.Register(CreateThreadForm{})
|
|
gob.Register(CreateCommentForm{})
|
|
gob.Register(FormErrors{})
|
|
}
|
|
|
|
type FormErrors map[string]string
|
|
|
|
type CreatePostForm struct {
|
|
Title string
|
|
Content string
|
|
|
|
Errors FormErrors
|
|
}
|
|
|
|
func (f *CreatePostForm) Validate() bool {
|
|
f.Errors = FormErrors{}
|
|
|
|
if f.Title == "" {
|
|
f.Errors["Title"] = "Please enter a title!"
|
|
}
|
|
if f.Content == "" {
|
|
f.Errors["Content"] = "Please enter a text!"
|
|
}
|
|
|
|
return len(f.Errors) == 0
|
|
}
|
|
|
|
type CreateThreadForm struct {
|
|
Title string
|
|
Description string
|
|
|
|
Errors FormErrors
|
|
}
|
|
|
|
func (f *CreateThreadForm) Validate() bool {
|
|
f.Errors = FormErrors{}
|
|
|
|
if f.Title == "" {
|
|
f.Errors["Title"] = "Please enter a title!"
|
|
}
|
|
if f.Description == "" {
|
|
f.Errors["Description"] = "Please enter a description!"
|
|
}
|
|
|
|
return len(f.Errors) == 0
|
|
}
|
|
|
|
type CreateCommentForm struct {
|
|
Content string
|
|
|
|
Errors FormErrors
|
|
}
|
|
|
|
func (f *CreateCommentForm) Validate() bool {
|
|
f.Errors = FormErrors{}
|
|
|
|
if f.Content == "" {
|
|
f.Errors["Content"] = "Please enter a comment!"
|
|
}
|
|
|
|
return len(f.Errors) == 0
|
|
}
|