Note that this does not handle ports yet, so development environments are out.
(s string)
| 222 | |
| 223 | // Note that this does not handle ports yet, so development environments are out. |
| 224 | func parseAPIHost(s string) (APIHost, error) { |
| 225 | if s == "" { |
| 226 | return newDotcomHost() |
| 227 | } |
| 228 | |
| 229 | u, err := url.Parse(s) |
| 230 | if err != nil { |
| 231 | return APIHost{}, fmt.Errorf("could not parse host as URL: %s", s) |
| 232 | } |
| 233 | |
| 234 | if u.Scheme == "" { |
| 235 | return APIHost{}, fmt.Errorf("host must have a scheme (http or https): %s", s) |
| 236 | } |
| 237 | |
| 238 | if u.Hostname() == "github.com" || strings.HasSuffix(u.Hostname(), ".github.com") { |
| 239 | return newDotcomHost() |
| 240 | } |
| 241 | |
| 242 | if u.Hostname() == "ghe.com" || strings.HasSuffix(u.Hostname(), ".ghe.com") { |
| 243 | return newGHECHost(s) |
| 244 | } |
| 245 | |
| 246 | return newGHESHost(s) |
| 247 | } |