From 7e4494256a08f585523e01b1bbc51f41ff4e2b95 Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Mon, 26 Sep 2022 14:50:22 +0200 Subject: Refactor: Errors into custom export types and expose types --- internal/types/server.go | 69 ------------------------------------------------ 1 file changed, 69 deletions(-) delete mode 100644 internal/types/server.go (limited to 'internal/types/server.go') diff --git a/internal/types/server.go b/internal/types/server.go deleted file mode 100644 index 48f94fb..0000000 --- a/internal/types/server.go +++ /dev/null @@ -1,69 +0,0 @@ -package types - -import ( - "encoding/json" - "time" -) - -// Shared server types - -// Structs that define the json format for -// url: "https://disco.eduvpn.org/v2/organization_list.json" -type DiscoveryOrganizations struct { - Version uint64 `json:"v"` - List []DiscoveryOrganization `json:"organization_list"` - Timestamp time.Time `json:"go_timestamp"` - RawString string `json:"go_raw_string"` -} - -type DiscoveryOrganization struct { - DisplayName DiscoMapOrString `json:"display_name"` - OrgId string `json:"org_id"` - SecureInternetHome string `json:"secure_internet_home"` - KeywordList DiscoMapOrString `json:"keyword_list"` -} - -// Structs that define the json format for -// url: "https://disco.eduvpn.org/v2/server_list.json" -type DiscoveryServers struct { - Version uint64 `json:"v"` - List []DiscoveryServer `json:"server_list"` - Timestamp time.Time `json:"go_timestamp"` - RawString string `json:"go_raw_string"` -} - -type DiscoMapOrString map[string]string - -// The display name can either be a map or a string in the server list -// Unmarshal it by first trying a string and then the map -func (DN *DiscoMapOrString) UnmarshalJSON(data []byte) error { - var displayNameString string - - err := json.Unmarshal(data, &displayNameString) - - if err == nil { - *DN = map[string]string{"en": displayNameString} - return nil - } - - var resultingMap map[string]string - - err = json.Unmarshal(data, &resultingMap) - - if err == nil { - *DN = resultingMap - return nil - } - return err -} - -type DiscoveryServer struct { - AuthenticationURLTemplate string `json:"authentication_url_template"` - BaseURL string `json:"base_url"` - CountryCode string `json:"country_code"` - DisplayName DiscoMapOrString `json:"display_name,omitempty"` - KeywordList DiscoMapOrString `json:"keyword_list"` - PublicKeyList []string `json:"public_key_list"` - Type string `json:"server_type"` - SupportContact []string `json:"support_contact"` -} -- cgit v1.2.3