File
Blob: tun/client/dialer/apex.go
| 1 | package dialer |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strconv" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | type ParsedApex struct { |
| 10 | Host string `json:"host"` |
| 11 | Port int `json:"port"` |
| 12 | } |
| 13 | |
| 14 | func (p *ParsedApex) String() string { |
| 15 | return fmt.Sprintf("%s:%d", p.Host, p.Port) |
| 16 | } |
| 17 | |
| 18 | func ParseApex(apex string) (*ParsedApex, error) { |
| 19 | port := 443 |
| 20 | i := strings.Index(apex, ":") |
| 21 | if i != -1 { |
| 22 | nP, err := strconv.ParseInt(apex[i+1:], 0, 32) |
| 23 | if err != nil { |
| 24 | return nil, fmt.Errorf("error parsing port number: %w", err) |
| 25 | } |
| 26 | apex = apex[:i] |
| 27 | port = int(nP) |
| 28 | } |
| 29 | return &ParsedApex{ |
| 30 | Host: apex, |
| 31 | Port: port, |
| 32 | }, nil |
| 33 | } |