Skip to content

Commit 578ffba

Browse files
committed
chore: apply gofmt
1 parent aa3cf11 commit 578ffba

4 files changed

Lines changed: 122 additions & 127 deletions

File tree

internal/config/config.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
package config
22

33
import (
4-
"time"
4+
"time"
55
)
66

77
// Config holds the internal configuration settings
88
type Config struct {
9-
APIVersion string
10-
DefaultTimeout time.Duration
11-
MaxRetries int
12-
UserAgent string
13-
Endpoints Endpoints
9+
APIVersion string
10+
DefaultTimeout time.Duration
11+
MaxRetries int
12+
UserAgent string
13+
Endpoints Endpoints
1414
}
1515

1616
// Endpoints holds all API endpoint paths
1717
type Endpoints struct {
18-
Auth AuthEndpoints
19-
Users UsersEndpoints
18+
Auth AuthEndpoints
19+
Users UsersEndpoints
2020
}
2121

2222
type AuthEndpoints struct {
23-
Validate string
24-
Token string
23+
Validate string
24+
Token string
2525
}
2626

2727
type UsersEndpoints struct {
28-
Get string
29-
Update string
30-
Delete string
28+
Get string
29+
Update string
30+
Delete string
3131
}
3232

3333
// NewConfig returns a new configuration with default values
3434
func NewConfig() *Config {
35-
return &Config{
36-
APIVersion: "v1",
37-
DefaultTimeout: 30 * time.Second,
38-
MaxRetries: 3,
39-
UserAgent: "rownd-go-sdk/1.0",
40-
Endpoints: Endpoints{
41-
Auth: AuthEndpoints{
42-
Validate: "/hub/auth/validate",
43-
Token: "/hub/auth/token",
44-
},
45-
Users: UsersEndpoints{
46-
Get: "/hub/users/%s",
47-
Update: "/hub/users/%s",
48-
Delete: "/hub/users/%s",
49-
},
50-
},
51-
}
52-
}
35+
return &Config{
36+
APIVersion: "v1",
37+
DefaultTimeout: 30 * time.Second,
38+
MaxRetries: 3,
39+
UserAgent: "rownd-go-sdk/1.0",
40+
Endpoints: Endpoints{
41+
Auth: AuthEndpoints{
42+
Validate: "/hub/auth/validate",
43+
Token: "/hub/auth/token",
44+
},
45+
Users: UsersEndpoints{
46+
Get: "/hub/users/%s",
47+
Update: "/hub/users/%s",
48+
Delete: "/hub/users/%s",
49+
},
50+
},
51+
}
52+
}

internal/testutils/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ package testutils
22

33
// Client defines the interface needed for auth operations
44
type Client interface {
5-
GetBaseURL() string
6-
GetAppKey() string
7-
}
5+
GetBaseURL() string
6+
GetAppKey() string
7+
}

internal/utils/http.go

Lines changed: 87 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,114 @@
11
package utils
22

33
import (
4-
"bytes"
5-
"context"
6-
"encoding/json"
7-
"fmt"
8-
"io"
9-
"net/http"
10-
"time"
4+
"bytes"
5+
"context"
6+
"encoding/json"
7+
"fmt"
8+
"io"
9+
"net/http"
10+
"time"
1111
)
1212

1313
// HTTPClient wraps the standard http.Client with additional functionality
1414
type HTTPClient struct {
15-
client *http.Client
16-
maxRetries int
15+
client *http.Client
16+
maxRetries int
1717
}
1818

1919
// RequestOptions contains options for making HTTP requests
2020
type RequestOptions struct {
21-
Headers map[string]string
22-
Query map[string]string
23-
Timeout time.Duration
21+
Headers map[string]string
22+
Query map[string]string
23+
Timeout time.Duration
2424
}
2525

2626
// NewHTTPClient creates a new HTTP client with the specified configuration
2727
func NewHTTPClient(timeout time.Duration, maxRetries int) *HTTPClient {
28-
return &HTTPClient{
29-
client: &http.Client{
30-
Timeout: timeout,
31-
},
32-
maxRetries: maxRetries,
33-
}
28+
return &HTTPClient{
29+
client: &http.Client{
30+
Timeout: timeout,
31+
},
32+
maxRetries: maxRetries,
33+
}
3434
}
3535

3636
// DoRequest performs an HTTP request with retries and error handling
3737
func (c *HTTPClient) DoRequest(ctx context.Context, method, url string, body interface{}, opts *RequestOptions) (*http.Response, error) {
38-
var bodyReader io.Reader
39-
if body != nil {
40-
jsonBody, err := json.Marshal(body)
41-
if err != nil {
42-
return nil, fmt.Errorf("failed to marshal request body: %w", err)
43-
}
44-
bodyReader = bytes.NewBuffer(jsonBody)
45-
}
46-
47-
req, err := http.NewRequestWithContext(ctx, method, url, bodyReader)
48-
if err != nil {
49-
return nil, fmt.Errorf("failed to create request: %w", err)
50-
}
51-
52-
// Apply options
53-
if opts != nil {
54-
// Add headers
55-
for key, value := range opts.Headers {
56-
req.Header.Set(key, value)
57-
}
58-
59-
// Add query parameters
60-
q := req.URL.Query()
61-
for key, value := range opts.Query {
62-
q.Add(key, value)
63-
}
64-
req.URL.RawQuery = q.Encode()
65-
}
66-
67-
// Set default headers
68-
if req.Header.Get("Content-Type") == "" {
69-
req.Header.Set("Content-Type", "application/json")
70-
}
71-
72-
// Perform request with retries
73-
var resp *http.Response
74-
var lastErr error
75-
76-
for attempt := 0; attempt <= c.maxRetries; attempt++ {
77-
resp, lastErr = c.client.Do(req)
78-
if lastErr == nil {
79-
break
80-
}
81-
82-
// Check if context is cancelled
83-
if ctx.Err() != nil {
84-
return nil, ctx.Err()
85-
}
86-
87-
// Wait before retrying
88-
if attempt < c.maxRetries {
89-
time.Sleep(time.Duration(attempt+1) * time.Second)
90-
}
91-
}
92-
93-
if lastErr != nil {
94-
return nil, fmt.Errorf("request failed after %d retries: %w", c.maxRetries, lastErr)
95-
}
96-
97-
return resp, nil
38+
var bodyReader io.Reader
39+
if body != nil {
40+
jsonBody, err := json.Marshal(body)
41+
if err != nil {
42+
return nil, fmt.Errorf("failed to marshal request body: %w", err)
43+
}
44+
bodyReader = bytes.NewBuffer(jsonBody)
45+
}
46+
47+
req, err := http.NewRequestWithContext(ctx, method, url, bodyReader)
48+
if err != nil {
49+
return nil, fmt.Errorf("failed to create request: %w", err)
50+
}
51+
52+
// Apply options
53+
if opts != nil {
54+
// Add headers
55+
for key, value := range opts.Headers {
56+
req.Header.Set(key, value)
57+
}
58+
59+
// Add query parameters
60+
q := req.URL.Query()
61+
for key, value := range opts.Query {
62+
q.Add(key, value)
63+
}
64+
req.URL.RawQuery = q.Encode()
65+
}
66+
67+
// Set default headers
68+
if req.Header.Get("Content-Type") == "" {
69+
req.Header.Set("Content-Type", "application/json")
70+
}
71+
72+
// Perform request with retries
73+
var resp *http.Response
74+
var lastErr error
75+
76+
for attempt := 0; attempt <= c.maxRetries; attempt++ {
77+
resp, lastErr = c.client.Do(req)
78+
if lastErr == nil {
79+
break
80+
}
81+
82+
// Check if context is cancelled
83+
if ctx.Err() != nil {
84+
return nil, ctx.Err()
85+
}
86+
87+
// Wait before retrying
88+
if attempt < c.maxRetries {
89+
time.Sleep(time.Duration(attempt+1) * time.Second)
90+
}
91+
}
92+
93+
if lastErr != nil {
94+
return nil, fmt.Errorf("request failed after %d retries: %w", c.maxRetries, lastErr)
95+
}
96+
97+
return resp, nil
9898
}
9999

100100
// DecodeResponse decodes the response body into the provided interface
101101
func DecodeResponse(resp *http.Response, v interface{}) error {
102-
defer resp.Body.Close()
102+
defer resp.Body.Close()
103103

104-
if resp.StatusCode >= 400 {
105-
body, _ := io.ReadAll(resp.Body)
106-
return fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body))
107-
}
104+
if resp.StatusCode >= 400 {
105+
body, _ := io.ReadAll(resp.Body)
106+
return fmt.Errorf("request failed with status %d: %s", resp.StatusCode, string(body))
107+
}
108108

109-
if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
110-
return fmt.Errorf("failed to decode response: %w", err)
111-
}
109+
if err := json.NewDecoder(resp.Body).Decode(v); err != nil {
110+
return fmt.Errorf("failed to decode response: %w", err)
111+
}
112112

113-
return nil
113+
return nil
114114
}
115-

pkg/rownd/token.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222

2323
// Token ...
2424
type Token struct {
25-
Token *jwt.Token `json:"-"` // The parsed JWT token
25+
Token *jwt.Token `json:"-"` // The parsed JWT token
2626
UserID string `json:"user_id"`
2727
AccessToken string `json:"access_token"`
2828
Claims Claims `json:"decoded_token"`
@@ -191,13 +191,11 @@ func (c *Client) ValidateToken(ctx context.Context, token string) (*Token, error
191191
return validator.Validate(ctx, token)
192192
}
193193

194-
195194
// Add JWKS types
196195
type JWKS struct {
197196
Keys []JWK `json:"keys"`
198197
}
199198

200-
201199
// Add method to find key by KID
202200
func (j *JWKS) Contains(kid string) (*JWK, bool) {
203201
for _, key := range j.Keys {
@@ -207,5 +205,3 @@ func (j *JWKS) Contains(kid string) (*JWK, bool) {
207205
}
208206
return nil, false
209207
}
210-
211-

0 commit comments

Comments
 (0)