Skip to content

Commit

Permalink
Fix lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Piszmog committed Nov 30, 2024
1 parent ad5573d commit 35fa63b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func Basic(client *http.Client, username, password string, urls ...string) Optio
}

func newSimpleClient(client *http.Client, auth string, urls []string) []*HTTPClient {
clients := make([]*HTTPClient, len(urls), len(urls))
for index, baseUrl := range urls {
clients[index] = &HTTPClient{BaseURL: baseUrl, Client: client, Authorization: auth}
clients := make([]*HTTPClient, len(urls))
for index, baseURL := range urls {
clients[index] = &HTTPClient{BaseURL: baseURL, Client: client, Authorization: auth}
}
return clients
}
Expand Down Expand Up @@ -147,26 +147,26 @@ func newCloudClientForService(name string, services map[string][]cfservices.Serv
if err != nil {
return nil, fmt.Errorf("failed to create cloud Client: %w", err)
}
clients := make([]*HTTPClient, len(creds.Credentials), len(creds.Credentials))
clients := make([]*HTTPClient, len(creds.Credentials))
for i, cred := range creds.Credentials {
clients[i] = &HTTPClient{BaseURL: cred.Uri, Client: newOAuth2Client(cred.ClientId, cred.ClientSecret, cred.AccessTokenUri)}
}
return clients, nil
}

// OAuth2 creates a Client for a Config Server based on the provided OAuth2.0 information.
func OAuth2(baseURL string, clientId string, secret string, tokenURI string) Option {
func OAuth2(baseURL string, clientID string, secret string, tokenURI string) Option {
return func(clients *[]*HTTPClient) error {
*clients = append(*clients, &HTTPClient{BaseURL: baseURL, Client: newOAuth2Client(clientId, secret, tokenURI)})
*clients = append(*clients, &HTTPClient{BaseURL: baseURL, Client: newOAuth2Client(clientID, secret, tokenURI)})
return nil
}
}

func newOAuth2Client(clientId string, secret string, tokenURI string) *http.Client {
config := newOAuth2Config(clientId, secret, tokenURI)
func newOAuth2Client(clientID string, secret string, tokenURI string) *http.Client {
config := newOAuth2Config(clientID, secret, tokenURI)
return config.Client(context.Background())
}

func newOAuth2Config(clientId string, secret string, tokenURI string) *clientcredentials.Config {
return &clientcredentials.Config{ClientID: clientId, ClientSecret: secret, TokenURL: tokenURI}
func newOAuth2Config(clientID string, secret string, tokenURI string) *clientcredentials.Config {
return &clientcredentials.Config{ClientID: clientID, ClientSecret: secret, TokenURL: tokenURI}
}
4 changes: 2 additions & 2 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *Source) HandlePropertySources(handler PropertySourceHandler) {
// This function is not optimized (ugly) and is intended to only be used at startup.
func (s *Source) Unmarshal(v interface{}) error {
// covert to a map[string]interface{} so we can convert to the target type
obj, err := toJson(s.PropertySources)
obj, err := toJSON(s.PropertySources)
if err != nil {
return err
}
Expand All @@ -77,7 +77,7 @@ func (s *Source) Unmarshal(v interface{}) error {

var sliceRegex = regexp.MustCompile(`(.*)\[(\d+)]`)

func toJson(propertySources []PropertySource) (map[string]interface{}, error) {
func toJSON(propertySources []PropertySource) (map[string]interface{}, error) {
// get ready for a wild ride...
output := map[string]interface{}{}
// save the root, so we can get back there when we walk the tree
Expand Down
20 changes: 10 additions & 10 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,40 +105,40 @@ func (h *HTTPClient) GetResourceRaw(paths []string, params map[string]string) ([

// Get performs a http.MethodGet operation. Builds the URL based on the provided paths and params.
func (h *HTTPClient) Get(paths []string, params map[string]string) (*http.Response, error) {
fullUrl, err := newURL(h.BaseURL, paths, params)
fullURL, err := newURL(h.BaseURL, paths, params)
if err != nil {
return nil, fmt.Errorf("failed to create url: %w", err)
}
req, err := http.NewRequest(http.MethodGet, fullUrl, nil)
req, err := http.NewRequest(http.MethodGet, fullURL, nil)
if err != nil {
return nil, fmt.Errorf("failed to create request for %s: %w", fullUrl, err)
return nil, fmt.Errorf("failed to create request for %s: %w", fullURL, err)
}
if h.Authorization != "" {
req.Header.Set("Authorization", h.Authorization)
}
response, err := h.Do(req)
if err != nil {
return nil, fmt.Errorf("failed to retrieve from %s: %w", fullUrl, err)
return nil, fmt.Errorf("failed to retrieve from %s: %w", fullURL, err)
}
return response, nil
}

func newURL(baseURL string, paths []string, params map[string]string) (string, error) {
parseUrl, err := url.Parse(baseURL)
parseURL, err := url.Parse(baseURL)
if err != nil {
return "", fmt.Errorf("failed to parse url %s: %w", baseURL, err)
}
if paths != nil {
if len(paths) > 0 {
for _, p := range paths {
parseUrl.Path = path.Join(parseUrl.Path, p)
parseURL.Path = path.Join(parseURL.Path, p)
}
}
if params != nil {
query := parseUrl.Query()
query := parseURL.Query()
for key, value := range params {
query.Set(key, value)
}
parseUrl.RawQuery = query.Encode()
parseURL.RawQuery = query.Encode()
}
return parseUrl.String(), nil
return parseURL.String(), nil
}

0 comments on commit 35fa63b

Please sign in to comment.