Improved code by updating any interfaces
Change-Id: I9a2e630c37f3c427569f5bbd773978c2705dc08c
diff --git a/service/client.go b/service/client.go
index bdc9d8b..0ea0b94 100644
--- a/service/client.go
+++ b/service/client.go
@@ -139,7 +139,7 @@
}
// Post performs a POST request to the specified endpoint with JSON body
-func (c *Client) Post(ctx context.Context, endpoint string, body interface{}) (*http.Response, error) {
+func (c *Client) Post(ctx context.Context, endpoint string, body any) (*http.Response, error) {
var bodyReader io.Reader
if body != nil {
jsonBody, err := json.Marshal(body)
@@ -153,7 +153,7 @@
}
// GetJSON performs a GET request and unmarshals the JSON response
-func (c *Client) GetJSON(ctx context.Context, endpoint string, target interface{}) error {
+func (c *Client) GetJSON(ctx context.Context, endpoint string, target any) error {
resp, err := c.Get(ctx, endpoint)
if err != nil {
return err
@@ -172,7 +172,7 @@
}
// PostJSON performs a POST request and unmarshals the JSON response
-func (c *Client) PostJSON(ctx context.Context, endpoint string, body interface{}, target interface{}) error {
+func (c *Client) PostJSON(ctx context.Context, endpoint string, body any, target any) error {
resp, err := c.Post(ctx, endpoint, body)
if err != nil {
return err
diff --git a/service/client_test.go b/service/client_test.go
index 3827b09..0009d71 100644
--- a/service/client_test.go
+++ b/service/client_test.go
@@ -164,7 +164,7 @@
})
t.Run("Error handling", func(t *testing.T) {
- var result map[string]interface{}
+ var result map[string]any
err := client.GetJSON(ctx, "/error", &result)
assert.Error(t, err)
@@ -189,7 +189,7 @@
if r.URL.Path == "/token" {
// Mock token endpoint
w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(map[string]interface{}{
+ json.NewEncoder(w).Encode(map[string]any{
"access_token": "test-access-token",
"token_type": "Bearer",
"expires_in": 3600,
@@ -232,7 +232,7 @@
ctx := context.Background()
t.Run("Unauthenticated request", func(t *testing.T) {
- var result map[string]interface{}
+ var result map[string]any
err := client.GetJSON(ctx, "/", &result)
assert.Error(t, err)
@@ -251,7 +251,7 @@
})
t.Run("Authenticated request", func(t *testing.T) {
- var result map[string]interface{}
+ var result map[string]any
err := client.GetJSON(ctx, "/", &result)
assert.NoError(t, err)
diff --git a/service/types.go b/service/types.go
index a6151b6..cb1aed0 100644
--- a/service/types.go
+++ b/service/types.go
@@ -42,14 +42,14 @@
// SearchMeta contains metadata about the search results
type SearchMeta struct {
- Count int `json:"count"`
- StartIndex int `json:"startIndex"`
- ItemsPerPage int `json:"itemsPerPage"`
- TotalResults int `json:"totalResults"`
- SearchTime float64 `json:"searchTime,omitempty"`
- Benchmark string `json:"benchmark,omitempty"`
- Context string `json:"context,omitempty"`
- CorpusStatistics map[string]interface{} `json:"corpusStatistics,omitempty"`
+ Count int `json:"count"`
+ StartIndex int `json:"startIndex"`
+ ItemsPerPage int `json:"itemsPerPage"`
+ TotalResults int `json:"totalResults"`
+ SearchTime float64 `json:"searchTime,omitempty"`
+ Benchmark string `json:"benchmark,omitempty"`
+ Context string `json:"context,omitempty"`
+ CorpusStatistics map[string]any `json:"corpusStatistics,omitempty"`
}
// SearchQuery contains information about the executed query
@@ -63,19 +63,19 @@
// SearchMatch represents a single search result match
type SearchMatch struct {
- Field string `json:"field"`
- PubPlace string `json:"pubPlace,omitempty"`
- TextSigle string `json:"textSigle"`
- UID int `json:"UID"`
- MatchID string `json:"matchID"`
- Snippet string `json:"snippet"`
- LeftContext []ContextToken `json:"leftContext,omitempty"`
- RightContext []ContextToken `json:"rightContext,omitempty"`
- Position int `json:"position"`
- StartMore bool `json:"startMore,omitempty"`
- EndMore bool `json:"endMore,omitempty"`
- Match []MatchToken `json:"match,omitempty"`
- Fields map[string]interface{} `json:"fields,omitempty"`
+ Field string `json:"field"`
+ PubPlace string `json:"pubPlace,omitempty"`
+ TextSigle string `json:"textSigle"`
+ UID int `json:"UID"`
+ MatchID string `json:"matchID"`
+ Snippet string `json:"snippet"`
+ LeftContext []ContextToken `json:"leftContext,omitempty"`
+ RightContext []ContextToken `json:"rightContext,omitempty"`
+ Position int `json:"position"`
+ StartMore bool `json:"startMore,omitempty"`
+ EndMore bool `json:"endMore,omitempty"`
+ Match []MatchToken `json:"match,omitempty"`
+ Fields map[string]any `json:"fields,omitempty"`
}
// ContextToken represents a token in the context
@@ -98,14 +98,14 @@
// CorpusInfo represents information about a corpus
type CorpusInfo struct {
- ID string `json:"id"`
- Name string `json:"name"`
- Description string `json:"description,omitempty"`
- Documents int `json:"documents,omitempty"`
- Tokens int `json:"tokens,omitempty"`
- Sentences int `json:"sentences,omitempty"`
- Paragraphs int `json:"paragraphs,omitempty"`
- Fields map[string]interface{} `json:"fields,omitempty"`
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Description string `json:"description,omitempty"`
+ Documents int `json:"documents,omitempty"`
+ Tokens int `json:"tokens,omitempty"`
+ Sentences int `json:"sentences,omitempty"`
+ Paragraphs int `json:"paragraphs,omitempty"`
+ Fields map[string]any `json:"fields,omitempty"`
}
// CorpusListResponse represents the response for corpus listing
@@ -115,9 +115,9 @@
// StatisticsResponse represents corpus statistics
type StatisticsResponse struct {
- Documents int `json:"documents"`
- Tokens int `json:"tokens"`
- Sentences int `json:"sentences,omitempty"`
- Paragraphs int `json:"paragraphs,omitempty"`
- Fields map[string]interface{} `json:"fields,omitempty"`
+ Documents int `json:"documents"`
+ Tokens int `json:"tokens"`
+ Sentences int `json:"sentences,omitempty"`
+ Paragraphs int `json:"paragraphs,omitempty"`
+ Fields map[string]any `json:"fields,omitempty"`
}