diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-03-20 13:59:06 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2023-09-25 09:43:37 +0200 |
| commit | 3618f2337bf0099d1fe8e4782cda3677ea4175be (patch) | |
| tree | 638fa68f28c20178a729ef991e470d8d8aa9ee64 /types | |
| parent | 8ccb4486cdb03cd3b10606b4bd77b7bcb4107e6d (diff) | |
Types: Split discovery into its own package
Diffstat (limited to 'types')
| -rw-r--r-- | types/discovery/discovery.go | 65 | ||||
| -rw-r--r-- | types/types.go | 64 |
2 files changed, 65 insertions, 64 deletions
diff --git a/types/discovery/discovery.go b/types/discovery/discovery.go new file mode 100644 index 0000000..390cb43 --- /dev/null +++ b/types/discovery/discovery.go @@ -0,0 +1,65 @@ +package discovery + +import ( + "encoding/json" + "time" +) + +// TODO: Discovery here is the same as the upstream discovery format, should we separate this as well? +// Defined in URL: "https://disco.eduvpn.org/v2/organization_list.json" +type Organizations struct { + Version uint64 `json:"v"` + List []Organization `json:"organization_list,omitempty"` + Timestamp time.Time `json:"go_timestamp"` +} + +type Organization struct { + DisplayName MapOrString `json:"display_name,omitempty"` + OrgID string `json:"org_id"` + SecureInternetHome string `json:"secure_internet_home,omitempty"` + KeywordList MapOrString `json:"keyword_list,omitempty"` +} + +// Structs that define the json format for +// url: "https://disco.eduvpn.org/v2/server_list.json" +type Servers struct { + Version uint64 `json:"v"` + List []Server `json:"server_list,omitempty"` + Timestamp time.Time `json:"go_timestamp"` +} + +type MapOrString 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 (displayName *MapOrString) UnmarshalJSON(data []byte) error { + var displayNameString string + + err := json.Unmarshal(data, &displayNameString) + + if err == nil { + *displayName = map[string]string{"en": displayNameString} + return nil + } + + var resultingMap map[string]string + + err = json.Unmarshal(data, &resultingMap) + + if err == nil { + *displayName = resultingMap + return nil + } + return err +} + +type Server struct { + AuthenticationURLTemplate string `json:"authentication_url_template"` + BaseURL string `json:"base_url"` + CountryCode string `json:"country_code"` + DisplayName MapOrString `json:"display_name,omitempty"` + KeywordList MapOrString `json:"keyword_list,omitempty"` + PublicKeyList []string `json:"public_key_list"` + Type string `json:"server_type"` + SupportContact []string `json:"support_contact"` +} diff --git a/types/types.go b/types/types.go index 4161108..bb04fdd 100644 --- a/types/types.go +++ b/types/types.go @@ -2,73 +2,9 @@ package types import ( - "encoding/json" - "time" - "github.com/eduvpn/eduvpn-common/types/protocol" ) -// TODO: Discovery here is the same as the upstream discovery format, should we separate this as well? -// 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,omitempty"` - Timestamp time.Time `json:"go_timestamp"` -} - -type DiscoveryOrganization struct { - DisplayName DiscoMapOrString `json:"display_name,omitempty"` - OrgID string `json:"org_id"` - SecureInternetHome string `json:"secure_internet_home,omitempty"` - KeywordList DiscoMapOrString `json:"keyword_list,omitempty"` -} - -// 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,omitempty"` - Timestamp time.Time `json:"go_timestamp"` -} - -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 (displayName *DiscoMapOrString) UnmarshalJSON(data []byte) error { - var displayNameString string - - err := json.Unmarshal(data, &displayNameString) - - if err == nil { - *displayName = map[string]string{"en": displayNameString} - return nil - } - - var resultingMap map[string]string - - err = json.Unmarshal(data, &resultingMap) - - if err == nil { - *displayName = 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,omitempty"` - PublicKeyList []string `json:"public_key_list"` - Type string `json:"server_type"` - SupportContact []string `json:"support_contact"` -} - type Expiry struct { StartTime int64 `json:"start_time"` EndTime int64 `json:"end_time"` |
