From 7acd4803d0ec82f26471bdb23a578a901e50dae3 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Thu, 22 Apr 2021 08:35:24 +0200 Subject: [PATCH] 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. --- types/zone.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 types/zone.go diff --git a/types/zone.go b/types/zone.go new file mode 100644 index 0000000..1177427 --- /dev/null +++ b/types/zone.go @@ -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 +}