Quellcode durchsuchen

fix: run go fix

See https://go.dev/blog/gofix
Frédéric Guillot vor 1 Monat
Ursprung
Commit
01888d8e32

+ 1 - 1
client/model.go

@@ -149,7 +149,7 @@ type Feed struct {
 	FeedURL                     string    `json:"feed_url"`
 	SiteURL                     string    `json:"site_url"`
 	Title                       string    `json:"title"`
-	CheckedAt                   time.Time `json:"checked_at,omitempty"`
+	CheckedAt                   time.Time `json:"checked_at"`
 	EtagHeader                  string    `json:"etag_header,omitempty"`
 	LastModifiedHeader          string    `json:"last_modified_header,omitempty"`
 	ParsingErrorMsg             string    `json:"parsing_error_message,omitempty"`

+ 31 - 31
internal/integration/linktaco/linktaco_test.go

@@ -50,7 +50,7 @@ func TestCreateBookmark(t *testing.T) {
 
 				// Parse and verify request
 				body, _ := io.ReadAll(r.Body)
-				var req map[string]interface{}
+				var req map[string]any
 				if err := json.Unmarshal(body, &req); err != nil {
 					t.Errorf("Failed to parse request body: %v", err)
 				}
@@ -62,9 +62,9 @@ func TestCreateBookmark(t *testing.T) {
 
 				// Return success response
 				w.WriteHeader(http.StatusOK)
-				json.NewEncoder(w).Encode(map[string]interface{}{
-					"data": map[string]interface{}{
-						"addLink": map[string]interface{}{
+				json.NewEncoder(w).Encode(map[string]any{
+					"data": map[string]any{
+						"addLink": map[string]any{
 							"id":    "123",
 							"url":   "https://example.com",
 							"title": "Test Article",
@@ -111,9 +111,9 @@ func TestCreateBookmark(t *testing.T) {
 			entryContent: "Content",
 			serverResponse: func(w http.ResponseWriter, r *http.Request) {
 				w.WriteHeader(http.StatusOK)
-				json.NewEncoder(w).Encode(map[string]interface{}{
-					"errors": []interface{}{
-						map[string]interface{}{
+				json.NewEncoder(w).Encode(map[string]any{
+					"errors": []any{
+						map[string]any{
 							"message": "Invalid input",
 						},
 					},
@@ -145,9 +145,9 @@ func TestCreateBookmark(t *testing.T) {
 			entryContent: "Content",
 			serverResponse: func(w http.ResponseWriter, r *http.Request) {
 				w.WriteHeader(http.StatusOK)
-				json.NewEncoder(w).Encode(map[string]interface{}{
-					"errors": []interface{}{
-						map[string]interface{}{
+				json.NewEncoder(w).Encode(map[string]any{
+					"errors": []any{
+						map[string]any{
 							"message": "PRIVATE visibility requires a paid LinkTaco account",
 						},
 					},
@@ -165,12 +165,12 @@ func TestCreateBookmark(t *testing.T) {
 			entryContent: strings.Repeat("a", 600), // Content longer than 500 chars
 			serverResponse: func(w http.ResponseWriter, r *http.Request) {
 				body, _ := io.ReadAll(r.Body)
-				var req map[string]interface{}
+				var req map[string]any
 				json.Unmarshal(body, &req)
 
 				// Check that description was truncated
-				variables := req["variables"].(map[string]interface{})
-				input := variables["input"].(map[string]interface{})
+				variables := req["variables"].(map[string]any)
+				input := variables["input"].(map[string]any)
 				description := input["description"].(string)
 
 				if len(description) != maxDescriptionLength {
@@ -178,9 +178,9 @@ func TestCreateBookmark(t *testing.T) {
 				}
 
 				w.WriteHeader(http.StatusOK)
-				json.NewEncoder(w).Encode(map[string]interface{}{
-					"data": map[string]interface{}{
-						"addLink": map[string]interface{}{"id": "123"},
+				json.NewEncoder(w).Encode(map[string]any{
+					"data": map[string]any{
+						"addLink": map[string]any{"id": "123"},
 					},
 				})
 			},
@@ -196,12 +196,12 @@ func TestCreateBookmark(t *testing.T) {
 			entryContent: "Content",
 			serverResponse: func(w http.ResponseWriter, r *http.Request) {
 				body, _ := io.ReadAll(r.Body)
-				var req map[string]interface{}
+				var req map[string]any
 				json.Unmarshal(body, &req)
 
 				// Check that only 10 tags were sent
-				variables := req["variables"].(map[string]interface{})
-				input := variables["input"].(map[string]interface{})
+				variables := req["variables"].(map[string]any)
+				input := variables["input"].(map[string]any)
 				tags := input["tags"].(string)
 
 				tagCount := len(strings.Split(tags, ","))
@@ -210,9 +210,9 @@ func TestCreateBookmark(t *testing.T) {
 				}
 
 				w.WriteHeader(http.StatusOK)
-				json.NewEncoder(w).Encode(map[string]interface{}{
-					"data": map[string]interface{}{
-						"addLink": map[string]interface{}{"id": "123"},
+				json.NewEncoder(w).Encode(map[string]any{
+					"data": map[string]any{
+						"addLink": map[string]any{"id": "123"},
 					},
 				})
 			},
@@ -326,7 +326,7 @@ func TestGraphQLMutation(t *testing.T) {
 	// Test that the GraphQL mutation is properly formatted
 	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		body, _ := io.ReadAll(r.Body)
-		var req map[string]interface{}
+		var req map[string]any
 		if err := json.Unmarshal(body, &req); err != nil {
 			t.Fatalf("Failed to parse request: %v", err)
 		}
@@ -349,12 +349,12 @@ func TestGraphQLMutation(t *testing.T) {
 		}
 
 		// Verify variables structure
-		variables, ok := req["variables"].(map[string]interface{})
+		variables, ok := req["variables"].(map[string]any)
 		if !ok {
 			t.Fatal("Missing variables field")
 		}
 
-		input, ok := variables["input"].(map[string]interface{})
+		input, ok := variables["input"].(map[string]any)
 		if !ok {
 			t.Fatal("Missing input in variables")
 		}
@@ -369,9 +369,9 @@ func TestGraphQLMutation(t *testing.T) {
 
 		// Return success
 		w.WriteHeader(http.StatusOK)
-		json.NewEncoder(w).Encode(map[string]interface{}{
-			"data": map[string]interface{}{
-				"addLink": map[string]interface{}{
+		json.NewEncoder(w).Encode(map[string]any{
+			"data": map[string]any{
+				"addLink": map[string]any{
 					"id": "123",
 				},
 			},
@@ -397,9 +397,9 @@ func BenchmarkCreateBookmark(b *testing.B) {
 	// Create a mock server that always returns success
 	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		w.WriteHeader(http.StatusOK)
-		json.NewEncoder(w).Encode(map[string]interface{}{
-			"data": map[string]interface{}{
-				"addLink": map[string]interface{}{
+		json.NewEncoder(w).Encode(map[string]any{
+			"data": map[string]any{
+				"addLink": map[string]any{
 					"id": "123",
 				},
 			},

+ 1 - 1
internal/integration/raindrop/raindrop.go

@@ -70,7 +70,7 @@ func (c *Client) CreateRaindrop(entryURL, entryTitle string) error {
 type raindrop struct {
 	Link       string     `json:"link"`
 	Title      string     `json:"title"`
-	Collection collection `json:"collection,omitempty"`
+	Collection collection `json:"collection"`
 	Tags       []string   `json:"tags"`
 }
 

+ 7 - 7
internal/integration/readeck/readeck_test.go

@@ -98,11 +98,11 @@ func TestCreateBookmark(t *testing.T) {
 				if !strings.HasPrefix(ct, "multipart/form-data;") {
 					t.Errorf("expected multipart/form-data, got %s", ct)
 				}
-				boundaryIdx := strings.Index(ct, "boundary=")
-				if boundaryIdx == -1 {
+				_, after, ok := strings.Cut(ct, "boundary=")
+				if !ok {
 					t.Fatalf("missing multipart boundary in Content-Type: %s", ct)
 				}
-				boundary := ct[boundaryIdx+len("boundary="):]
+				boundary := after
 				mr := multipart.NewReader(r.Body, boundary)
 
 				seenLabels := []string{}
@@ -132,12 +132,12 @@ func TestCreateBookmark(t *testing.T) {
 					case "resource":
 						// First line is JSON header, then newline, then content
 						all := string(data)
-						idx := strings.IndexByte(all, '\n')
-						if idx == -1 {
+						before, after, ok := strings.Cut(all, "\n")
+						if !ok {
 							t.Fatalf("resource content missing header separator")
 						}
-						headerJSON := all[:idx]
-						resourceBody = all[idx+1:]
+						headerJSON := before
+						resourceBody = after
 						if err := json.Unmarshal([]byte(headerJSON), &resourceHeader); err != nil {
 							t.Fatalf("invalid resource header JSON: %v", err)
 						}

+ 1 - 1
internal/integration/shaarli/shaarli.go

@@ -75,7 +75,7 @@ func (c *Client) CreateLink(entryURL, entryTitle string) error {
 
 func (c *Client) generateBearerToken() string {
 	header := base64.RawURLEncoding.EncodeToString([]byte(`{"typ":"JWT","alg":"HS512"}`))
-	payload := base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf(`{"iat":%d}`, time.Now().Unix())))
+	payload := base64.RawURLEncoding.EncodeToString(fmt.Appendf(nil, `{"iat":%d}`, time.Now().Unix()))
 	data := header + "." + payload
 
 	mac := hmac.New(sha512.New, []byte(c.apiSecret))

+ 1 - 2
internal/reader/filter/filter.go

@@ -238,8 +238,7 @@ func containsRegexPattern(pattern string, items []string) bool {
 func parseDuration(duration string) (time.Duration, error) {
 	// Handle common duration formats like "30d", "7d", "1h", "1m", etc.
 	// Go's time.ParseDuration doesn't support days, so we handle them manually
-	if strings.HasSuffix(duration, "d") {
-		daysStr := strings.TrimSuffix(duration, "d")
+	if daysStr, ok := strings.CutSuffix(duration, "d"); ok {
 		days := 0
 		if daysStr != "" {
 			var err error

+ 0 - 1
internal/reader/sanitizer/sanitizer_test.go

@@ -957,7 +957,6 @@ func TestAttrLowerCase(t *testing.T) {
 	}
 
 	for _, tc := range testCases {
-		tc := tc
 		t.Run(tc.name, func(t *testing.T) {
 			output := sanitizeHTMLWithDefaultOptions(baseURL, tc.input)
 			if tc.expected != output {

+ 0 - 1
internal/validator/subscription_test.go

@@ -33,7 +33,6 @@ func TestValidateSubscriptionDiscovery(t *testing.T) {
 	}
 
 	for _, tc := range tests {
-		tc := tc
 		t.Run(tc.name, func(t *testing.T) {
 			if err := ValidateSubscriptionDiscovery(tc.req); (err != nil) != tc.wantErr {
 				t.Fatalf("expected error %v, got %v", tc.wantErr, err)