add types package
This package will contain all the parameter types that need parsing from the outside world into internal types. Each type is required to implement its own UnmarshalJSON. At this point it should also make the checks, if the incoming data is valid input, but is not required to check against the database.
This commit is contained in:
parent
979164f4d2
commit
7acd4803d0
|
@ -0,0 +1,20 @@
|
|||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type (
|
||||
Zone string
|
||||
)
|
||||
|
||||
func (z *Zone) UnmarshalJSON(in []byte) error {
|
||||
in = bytes.Trim(in, `"`)
|
||||
|
||||
if in[len(in)-1] != '.' {
|
||||
return fmt.Errorf("not a valid zone name")
|
||||
}
|
||||
*z = Zone(in)
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue