1package probeservices 2 3// Metadata contains metadata about a probe. This message is 4// included into a bunch of messages sent to orchestra. 5type Metadata struct { 6 AvailableBandwidth string `json:"available_bandwidth,omitempty"` 7 DeviceToken string `json:"device_token,omitempty"` 8 Language string `json:"language,omitempty"` 9 NetworkType string `json:"network_type,omitempty"` 10 Platform string `json:"platform"` 11 ProbeASN string `json:"probe_asn"` 12 ProbeCC string `json:"probe_cc"` 13 ProbeFamily string `json:"probe_family,omitempty"` 14 ProbeTimezone string `json:"probe_timezone,omitempty"` 15 SoftwareName string `json:"software_name"` 16 SoftwareVersion string `json:"software_version"` 17 SupportedTests []string `json:"supported_tests"` 18} 19 20// Valid returns true if metadata is valid, false otherwise. Metadata is 21// considered valid if all the mandatory fields are not empty. If a field 22// is marked `json:",omitempty"` in the structure definition, then it's 23// for sure mandatory. The "device_token" field is mandatory only if the 24// platform is "ios" or "android", because there's currently no device 25// token that we know of for desktop devices. 26func (m Metadata) Valid() bool { 27 if m.ProbeCC == "" { 28 return false 29 } 30 if m.ProbeASN == "" { 31 return false 32 } 33 if m.Platform == "" { 34 return false 35 } 36 if m.SoftwareName == "" { 37 return false 38 } 39 if m.SoftwareVersion == "" { 40 return false 41 } 42 if len(m.SupportedTests) < 1 { 43 return false 44 } 45 switch m.Platform { 46 case "ios", "android": 47 if m.DeviceToken == "" { 48 return false 49 } 50 } 51 return true 52} 53