Skip to content

Commit f8b8a30

Browse files
committed
chore: run gofumpt
1 parent d251680 commit f8b8a30

30 files changed

+131
-112
lines changed

api_client.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ import (
3434
"time"
3535
)
3636

37-
const maxChunkSize = 8 * 1024 * 1024 // 8 MB chunk size
38-
const maxRetryCount = 3
39-
const initialRetryDelay = time.Second
40-
const delayMultiplier = 2
37+
const (
38+
maxChunkSize = 8 * 1024 * 1024 // 8 MB chunk size
39+
maxRetryCount = 3
40+
initialRetryDelay = time.Second
41+
delayMultiplier = 2
42+
)
4143

4244
type apiClient struct {
4345
clientConfig *ClientConfig
@@ -75,7 +77,6 @@ func sendStreamRequest[T responseStream[R], R any](ctx context.Context, ac *apiC
7577

7678
// sendRequest issues an API request and returns a map of the response contents.
7779
func sendRequest(ctx context.Context, ac *apiClient, path string, method string, body map[string]any, httpOptions *HTTPOptions) (map[string]any, error) {
78-
7980
req, httpOptions, err := buildRequest(ctx, ac, path, body, method, httpOptions)
8081
if err != nil {
8182
return nil, err
@@ -435,7 +436,7 @@ func iterateResponseStream[R any](rs *responseStream[R], responseConverter func(
435436
default:
436437
var err error
437438
if len(line) > 0 {
438-
var respWithError = new(responseWithError)
439+
respWithError := new(responseWithError)
439440
// Stream chunk that doesn't matches error format.
440441
if marshalErr := json.Unmarshal(line, respWithError); marshalErr != nil {
441442
err = fmt.Errorf("iterateResponseStream: invalid stream chunk: %s:%s", string(prefix), string(data))
@@ -479,7 +480,7 @@ type responseWithError struct {
479480
}
480481

481482
func newAPIError(resp *http.Response) error {
482-
var respWithError = new(responseWithError)
483+
respWithError := new(responseWithError)
483484
body, err := io.ReadAll(resp.Body)
484485
if err != nil {
485486
return fmt.Errorf("newAPIError: error reading response body: %w. Response: %v", err, string(body))
@@ -561,7 +562,7 @@ func (ac *apiClient) uploadFile(ctx context.Context, r io.Reader, uploadURL stri
561562
var offset int64 = 0
562563
var resp *http.Response
563564
var respBody map[string]any
564-
var uploadCommand = "upload"
565+
uploadCommand := "upload"
565566

566567
buffer := make([]byte, maxChunkSize)
567568
for {
@@ -641,7 +642,7 @@ func (ac *apiClient) uploadFile(ctx context.Context, r io.Reader, uploadURL stri
641642
return nil, fmt.Errorf("Failed to upload file: Upload status is not finalized")
642643
}
643644

644-
var response = new(File)
645+
response := new(File)
645646
err := mapToStruct(respBody["file"].(map[string]any), &response)
646647
if err != nil {
647648
return nil, err

api_client_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,13 @@ func TestMapToStruct(t *testing.T) {
658658
inputMap: map[string]any{
659659
"role": "test-role",
660660
"TokenIDs": []string{"123", "456"},
661-
"Tokens": [][]byte{[]byte("token1"), []byte("token2")}},
661+
"Tokens": [][]byte{[]byte("token1"), []byte("token2")},
662+
},
662663
wantValue: TokensInfo{
663664
Role: "test-role",
664665
TokenIDs: []int64{123, 456},
665-
Tokens: [][]byte{[]byte("token1"), []byte("token2")}},
666+
Tokens: [][]byte{[]byte("token1"), []byte("token2")},
667+
},
666668
},
667669
{
668670
name: "Citation",
@@ -705,7 +707,6 @@ func TestMapToStruct(t *testing.T) {
705707
outputValue := reflect.New(reflect.TypeOf(tc.wantValue)).Interface()
706708

707709
err := mapToStruct(tc.inputMap, &outputValue)
708-
709710
if err != nil {
710711
t.Fatalf("mapToStruct failed: %v", err)
711712
}
@@ -1504,7 +1505,6 @@ func TestUploadFile(t *testing.T) {
15041505
uploadURL := server.URL + "/upload"
15051506

15061507
uploadedFile, err := ac.uploadFile(ctx, fileReader, uploadURL, httpOpts)
1507-
15081508
if err != nil {
15091509
t.Fatalf("uploadFile failed: %v", err)
15101510
}
@@ -1530,7 +1530,6 @@ func TestUploadFile(t *testing.T) {
15301530
if uploadedFile.MIMEType != "text/plain" { // Matches mock server response
15311531
t.Errorf("uploadedFile.MIMEType mismatch: want 'text/plain', got '%s'", uploadedFile.MIMEType)
15321532
}
1533-
15341533
})
15351534
}
15361535
}

base_url.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
package genai
1616

17-
var defaultBaseGeminiURL string = ""
18-
var defaultBaseVertexURL string = ""
17+
var (
18+
defaultBaseGeminiURL string = ""
19+
defaultBaseVertexURL string = ""
20+
)
1921

2022
// BaseURLParameters are parameters for setting the base URLs for the Gemini API and Vertex AI API.
2123
type BaseURLParameters struct {

caches_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ func TestCachesAll(t *testing.T) {
9191
defer ts.Close()
9292

9393
// Create a client with the test server
94-
client, err := NewClient(context.Background(), &ClientConfig{HTTPOptions: HTTPOptions{BaseURL: ts.URL},
94+
client, err := NewClient(context.Background(), &ClientConfig{
95+
HTTPOptions: HTTPOptions{BaseURL: ts.URL},
9596
envVarProvider: func() map[string]string {
9697
return map[string]string{
9798
"GOOGLE_API_KEY": "test-api-key",

chats_test.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ func TestValidateContent(t *testing.T) {
3535
{"NilContent", nil, false},
3636
{"EmptyParts", &Content{Parts: []*Part{}}, false},
3737
{"NilPart", &Content{Parts: []*Part{nil}}, false},
38-
{"EmptyTextPart", &Content{Parts: []*Part{&Part{Text: ""}}}, false},
39-
{"ValidTextPart", &Content{Parts: []*Part{&Part{Text: "hello"}}}, true},
40-
{"ValidFunctionCall", &Content{Parts: []*Part{&Part{FunctionCall: &FunctionCall{Name: "test"}}}}, true},
38+
{"EmptyTextPart", &Content{Parts: []*Part{{Text: ""}}}, false},
39+
{"ValidTextPart", &Content{Parts: []*Part{{Text: "hello"}}}, true},
40+
{"ValidFunctionCall", &Content{Parts: []*Part{{FunctionCall: &FunctionCall{Name: "test"}}}}, true},
4141
}
4242

4343
for _, tt := range tests {
@@ -176,7 +176,6 @@ func TestChatsUnitTest(t *testing.T) {
176176
break
177177
}
178178
})
179-
180179
}
181180

182181
func TestChatsText(t *testing.T) {
@@ -316,16 +315,16 @@ func TestChatsHistory(t *testing.T) {
316315
// Create a new Chat with handwritten history.
317316
var config *GenerateContentConfig = &GenerateContentConfig{Temperature: Ptr[float32](0.5)}
318317
history := []*Content{
319-
&Content{
318+
{
320319
Role: "user",
321320
Parts: []*Part{
322-
&Part{Text: "What is 1 + 2?"},
321+
{Text: "What is 1 + 2?"},
323322
},
324323
},
325-
&Content{
324+
{
326325
Role: "model",
327326
Parts: []*Part{
328-
&Part{Text: "3"},
327+
{Text: "3"},
329328
},
330329
},
331330
}
@@ -721,10 +720,10 @@ data:{
721720
}
722721

723722
var expectedResponses []*Content
724-
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{&Part{Text: "text1_candidate1"}}})
725-
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{&Part{Text: " "}}})
726-
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{&Part{Text: "text3_candidate1"}, &Part{Text: " additional text3_candidate1 "}}})
727-
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{&Part{Text: "text4_candidate1"}, &Part{Text: " additional text4_candidate1"}}})
723+
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{{Text: "text1_candidate1"}}})
724+
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{{Text: " "}}})
725+
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{{Text: "text3_candidate1"}, {Text: " additional text3_candidate1 "}}})
726+
expectedResponses = append(expectedResponses, &Content{Role: "model", Parts: []*Part{{Text: "text4_candidate1"}, {Text: " additional text4_candidate1"}}})
728727

729728
history := chat.History(false)
730729
expectedUserMessage := "What is 1 + 2?"
@@ -738,6 +737,5 @@ data:{
738737
}
739738
}
740739
}
741-
742740
})
743741
}

0 commit comments

Comments
 (0)