MCPcopy Create free account
hub / github.com/Hidden-Node/GooseRelayVPN-AndroidClient / parseSNIHosts

Function parseSNIHosts

internal/config/client.go:258–288  ·  view source on GitHub ↗

parseSNIHosts parses the "sni" JSON field, which may be either a single string ("www.google.com") or an array (["www.google.com", "mail.google.com"]). Falls back to ["www.google.com"] when the field is absent or empty.

(raw json.RawMessage)

Source from the content-addressed store, hash-verified

256// string ("www.google.com") or an array (["www.google.com", "mail.google.com"]).
257// Falls back to ["www.google.com"] when the field is absent or empty.
258func parseSNIHosts(raw json.RawMessage) []string {
259 if len(raw) == 0 {
260 return []string{"www.google.com"}
261 }
262 // Try string first (backward-compatible single-SNI config).
263 var single string
264 if err := json.Unmarshal(raw, &single); err == nil {
265 single = strings.TrimSpace(single)
266 if single == "" {
267 return []string{"www.google.com"}
268 }
269 return []string{single}
270 }
271 // Try array.
272 var multi []string
273 if err := json.Unmarshal(raw, &multi); err != nil {
274 // Malformed — fall back to default and let the rest of validation catch it.
275 return []string{"www.google.com"}
276 }
277 out := make([]string, 0, len(multi))
278 for _, h := range multi {
279 h = strings.TrimSpace(h)
280 if h != "" {
281 out = append(out, h)
282 }
283 }
284 if len(out) == 0 {
285 return []string{"www.google.com"}
286 }
287 return out
288}
289
290// LoadClient reads and validates a client config file.
291func LoadClient(path string) (*Client, error) {

Callers 1

LoadClientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected