summaryrefslogtreecommitdiff
path: root/types/server/server.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2023-04-24 12:16:29 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2023-09-25 09:43:37 +0200
commita27988d8c7f7dbab95edf65da5482aec5d8067e4 (patch)
tree6753276b3c291ada561dbc8c2642493198a8face /types/server/server.go
parent6e12ee1b85c861ea9ed8edabee2f351a76a148c1 (diff)
Server: Support unmarshalling server as a string
This is for V1 configs
Diffstat (limited to 'types/server/server.go')
-rw-r--r--types/server/server.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/types/server/server.go b/types/server/server.go
index aea496d..3bdebe1 100644
--- a/types/server/server.go
+++ b/types/server/server.go
@@ -2,6 +2,9 @@
package server
import (
+ "encoding/json"
+ "fmt"
+
"github.com/eduvpn/eduvpn-common/types/cookie"
"github.com/eduvpn/eduvpn-common/types/protocol"
)
@@ -20,6 +23,36 @@ const (
TypeCustom
)
+// This is here to support V1 configs which had the server type as a string
+func (t *Type) UnmarshalJSON(data []byte) error {
+ // First try to just unmarshal the type
+ var num int8
+ if err := json.Unmarshal(data, &num); err == nil {
+ if num < int8(TypeUnknown) || num > int8(TypeCustom) {
+ return fmt.Errorf("invalid server type: %d", num)
+ }
+ *t = Type(num)
+ return nil
+ }
+
+ // unmarshal the old way, as a string
+ var str string
+ if err := json.Unmarshal(data, &str); err != nil {
+ return err
+ }
+ switch str {
+ case "secure_internet":
+ *t = TypeSecureInternet
+ case "institute_access":
+ *t = TypeInstituteAccess
+ case "custom_server":
+ *t = TypeCustom
+ default:
+ return fmt.Errorf("invalid server type: %s", str)
+ }
+ return nil
+}
+
// RequiredAskTransition represents the data that is sent when a transition is required to be handled and the go library needs data from the client
// This data can be a profile selection or secure internet location selection
type RequiredAskTransition struct {