Skip to content

Instantly share code, notes, and snippets.

@gerep
Created Dec 10, 2014
Embed
What would you like to do?
Go validation
package main
import (
"fmt"
)
type Validation struct {
Error string
OK bool
}
func (v Validation) Message(message string) string {
if v.OK == false {
return message
}
return ""
}
func (v Validation) MinSize(who string, size int) Validation {
if len(who) < size {
return Validation{OK: false}
}
return Validation{OK: true}
}
func (v Validation) MaxSize(who string, size int) Validation {
if len(who) > size {
return Validation{OK: false}
}
return Validation{OK: true}
}
func main() {
v := Validation{}
fmt.Println(v.MinSize("Daniel", 10).Message("Valor é muito pequeno"))
fmt.Println(v.MaxSize("Daniel", 10).Message("Valor é muito grande"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment