prepareAPIURL checks/fixes a LAPI connection url (http, https or socket) and returns an URL struct
(clientCfg *csconfig.LocalApiClientCfg, apiURL string)
| 82 | |
| 83 | // prepareAPIURL checks/fixes a LAPI connection url (http, https or socket) and returns an URL struct |
| 84 | func prepareAPIURL(clientCfg *csconfig.LocalApiClientCfg, apiURL string) (*url.URL, error) { |
| 85 | if apiURL == "" { |
| 86 | if clientCfg == nil || clientCfg.Credentials == nil || clientCfg.Credentials.URL == "" { |
| 87 | return nil, errors.New("no Local API URL. Please provide it in your configuration or with the -u parameter") |
| 88 | } |
| 89 | |
| 90 | apiURL = clientCfg.Credentials.URL |
| 91 | } |
| 92 | |
| 93 | // URL needs to end with /, but user doesn't care |
| 94 | if !strings.HasSuffix(apiURL, "/") { |
| 95 | apiURL += "/" |
| 96 | } |
| 97 | |
| 98 | // URL needs to start with http://, but user doesn't care |
| 99 | if !strings.HasPrefix(apiURL, "http://") && !strings.HasPrefix(apiURL, "https://") && !strings.HasPrefix(apiURL, "/") { |
| 100 | apiURL = "http://" + apiURL |
| 101 | } |
| 102 | |
| 103 | return url.Parse(apiURL) |
| 104 | } |
| 105 | |
| 106 | func (cli *cliLapi) newStatusCmd() *cobra.Command { |
| 107 | cmdLapiStatus := &cobra.Command{ |
searching dependent graphs…