impl config State and config Interval
This commit is contained in:
27
config/state.go
Normal file
27
config/state.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type State string
|
||||
|
||||
var States = map[int]State{
|
||||
27006: "NC",
|
||||
84058: "UT",
|
||||
}
|
||||
|
||||
func (state *State) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
for k := range States {
|
||||
if string(States[k]) == s {
|
||||
*state = States[k]
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return errors.New("unknown state " + s)
|
||||
}
|
||||
Reference in New Issue
Block a user