diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/types/types.go | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/pkg/types/types.go b/pkg/types/types.go index 601f818..4747db6 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -22,6 +22,10 @@ package types +import ( + "fmt" +) + // State Machine type State int @@ -45,11 +49,29 @@ func (s State) String() string { } } +func (s *State) FromString(str string) error { + switch str { + case "new": + *s = StateNew + case "settling": + *s = StateSettling + case "settled": + *s = StateSettled + default: + return fmt.Errorf("invalid state '%s'", str) + } + return nil +} + func (s State) MarshalText() (data []byte, err error) { data = []byte(s.String()) return } +func (s *State) UnmarshalText(data []byte) error { + return s.FromString(string(data)) +} + type Language string func (l Language) String() string { @@ -59,11 +81,24 @@ func (l Language) String() string { return string(l) } -func (s Language) MarshalText() (data []byte, err error) { - data = []byte(s.String()) +func (l *Language) FromString(str string) error { + if str == "none" { + *l = "" + } else { + *l = Language(str) + } + return nil +} + +func (l Language) MarshalText() (data []byte, err error) { + data = []byte(l.String()) return } +func (l *Language) UnmarshalText(data []byte) error { + return l.FromString(string(data)) +} + type FullState struct { State State Ratio float32 @@ -111,3 +146,10 @@ type WebSocketResponseLanguages struct { WebSocketResponseBase Languages []Language `json:"languages"` } + +type WebSocketResponseFull struct { + WebSocketResponseBase + ErrorString string `json:"error"` + WebState + Languages []Language `json:"languages"` +} |