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:
Gibheer 2021-04-22 08:35:24 +02:00
parent 979164f4d2
commit 7acd4803d0
1 changed files with 20 additions and 0 deletions

20
types/zone.go Normal file
View File

@ -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
}