MCPcopy
hub / github.com/perkeep/perkeep / getServer

Function getServer

pkg/client/config.go:268–292  ·  view source on GitHub ↗

getServer returns the server's URL found either as a command-line flag, or as the default server in the config file.

()

Source from the content-addressed store, hash-verified

266// getServer returns the server's URL found either as a command-line flag,
267// or as the default server in the config file.
268func 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
294func defaultServer() (string, error) {
295 configOnce.Do(parseConfig)

Callers 1

NewFunction · 0.85

Calls 4

cleanServerFunction · 0.85
isURLOrHostPortFunction · 0.85
defaultServerFunction · 0.85
PrintfMethod · 0.80

Tested by

no test coverage detected