MCPcopy Create free account
hub / github.com/cloudbase/garm / initAPIClient

Function initAPIClient

cmd/garm-cli/cmd/root.go:76–109  ·  view source on GitHub ↗
(baseURL, token string)

Source from the content-addressed store, hash-verified

74}
75
76func initAPIClient(baseURL, token string) {
77 baseURLParsed, err := url.Parse(baseURL)
78 if err != nil {
79 fmt.Printf("Failed to parse base url %s: %s", baseURL, err)
80 os.Exit(1)
81 }
82 apiPath, err := url.JoinPath(baseURLParsed.Path, apiClient.DefaultBasePath)
83 if err != nil {
84 fmt.Printf("Failed to join base url path %s with %s: %s", baseURLParsed.Path, apiClient.DefaultBasePath, err)
85 os.Exit(1)
86 }
87 if debug {
88 os.Setenv("SWAGGER_DEBUG", "true")
89 }
90 transportCfg := apiClient.DefaultTransportConfig().
91 WithHost(baseURLParsed.Host).
92 WithBasePath(apiPath).
93 WithSchemes([]string{baseURLParsed.Scheme})
94 apiCli = apiClient.NewHTTPClientWithConfig(nil, transportCfg)
95 authToken = openapiRuntimeClient.BearerToken(token)
96
97 joined, err := url.JoinPath(baseURL, apiClient.DefaultBasePath)
98 if err != nil {
99 fmt.Printf("Failed to join base url %s with %s: %s", baseURL, apiClient.DefaultBasePath, err)
100 os.Exit(1)
101 }
102 rawHTTPClient = &rawClient{
103 BaseURL: joined,
104 Token: token,
105 HTTPClient: &http.Client{
106 Timeout: 30 * time.Second,
107 },
108 }
109}
110
111func initConfig() {
112 var err error

Callers 3

init.goFile · 0.85
initConfigFunction · 0.85
profile.goFile · 0.85

Calls 3

WithSchemesMethod · 0.80
WithBasePathMethod · 0.80
WithHostMethod · 0.80

Tested by

no test coverage detected