getServer returns the server's URL found either as a command-line flag, or as the default server in the config file.
()
| 266 | // getServer returns the server's URL found either as a command-line flag, |
| 267 | // or as the default server in the config file. |
| 268 | func getServer() (string, error) { |
| 269 | if s := os.Getenv("CAMLI_SERVER"); s != "" { |
| 270 | return cleanServer(s) |
| 271 | } |
| 272 | if flagServer != "" { |
| 273 | if !isURLOrHostPort(flagServer) { |
| 274 | configOnce.Do(parseConfig) |
| 275 | serverConf, ok := config.Servers[flagServer] |
| 276 | if ok { |
| 277 | return serverConf.Server, nil |
| 278 | } |
| 279 | log.Printf("%q looks like a server alias, but no such alias found in config.", flagServer) |
| 280 | } else { |
| 281 | return cleanServer(flagServer) |
| 282 | } |
| 283 | } |
| 284 | server, err := defaultServer() |
| 285 | if err != nil { |
| 286 | return "", err |
| 287 | } |
| 288 | if server == "" { |
| 289 | return "", camtypes.ErrClientNoServer |
| 290 | } |
| 291 | return cleanServer(server) |
| 292 | } |
| 293 | |
| 294 | func defaultServer() (string, error) { |
| 295 | configOnce.Do(parseConfig) |
no test coverage detected