diff --git a/client.go b/client.go index 2b402102..36dcd849 100644 --- a/client.go +++ b/client.go @@ -37,7 +37,11 @@ type ClientInterface interface { GetAllRawIndexes() (resp []map[string]interface{}, err error) CreateIndex(config *IndexConfig) (resp *Task, err error) DeleteIndex(uid string) (resp *Task, err error) - GetKeys() (resp *Keys, err error) + CreateKey(request *Key) (resp *Key, err error) + GetKey(identifier string) (resp *Key, err error) + GetKeys() (resp *ResultKey, err error) + UpdateKey(identifier string, request *Key) (resp *Key, err error) + DeleteKey(identifier string) (resp bool, err error) GetAllStats() (resp *Stats, err error) CreateDump() (resp *Dump, err error) GetDumpStatus(dumpUID string) (resp *Dump, err error) @@ -109,8 +113,42 @@ func (c *Client) GetAllStats() (resp *Stats, err error) { return resp, nil } -func (c *Client) GetKeys() (resp *Keys, err error) { - resp = &Keys{} +func (c *Client) CreateKey(request *Key) (resp *Key, err error) { + parsedRequest := convertKeyToParsedKey(*request) + resp = &Key{} + req := internalRequest{ + endpoint: "/keys", + method: http.MethodPost, + contentType: contentTypeJSON, + withRequest: &parsedRequest, + withResponse: resp, + acceptedStatusCodes: []int{http.StatusCreated}, + functionName: "CreateKey", + } + if err := c.executeRequest(req); err != nil { + return nil, err + } + return resp, nil +} + +func (c *Client) GetKey(identifier string) (resp *Key, err error) { + resp = &Key{} + req := internalRequest{ + endpoint: "/keys/" + identifier, + method: http.MethodGet, + withRequest: nil, + withResponse: resp, + acceptedStatusCodes: []int{http.StatusOK}, + functionName: "GetKey", + } + if err := c.executeRequest(req); err != nil { + return nil, err + } + return resp, nil +} + +func (c *Client) GetKeys() (resp *ResultKey, err error) { + resp = &ResultKey{} req := internalRequest{ endpoint: "/keys", method: http.MethodGet, @@ -125,6 +163,39 @@ func (c *Client) GetKeys() (resp *Keys, err error) { return resp, nil } +func (c *Client) UpdateKey(identifier string, request *Key) (resp *Key, err error) { + parsedRequest := convertKeyToParsedKey(*request) + resp = &Key{} + req := internalRequest{ + endpoint: "/keys/" + identifier, + method: http.MethodPatch, + contentType: contentTypeJSON, + withRequest: &parsedRequest, + withResponse: resp, + acceptedStatusCodes: []int{http.StatusOK}, + functionName: "UpdateKey", + } + if err := c.executeRequest(req); err != nil { + return nil, err + } + return resp, nil +} + +func (c *Client) DeleteKey(identifier string) (resp bool, err error) { + req := internalRequest{ + endpoint: "/keys/" + identifier, + method: http.MethodDelete, + withRequest: nil, + withResponse: nil, + acceptedStatusCodes: []int{http.StatusNoContent}, + functionName: "DeleteKey", + } + if err := c.executeRequest(req); err != nil { + return false, err + } + return true, nil +} + func (c *Client) Health() (resp *Health, err error) { resp = &Health{} req := internalRequest{ @@ -243,3 +314,19 @@ func (c *Client) WaitForTask(task *Task, options ...waitParams) (*Task, error) { time.Sleep(options[0].Interval) } } + +// This function allows the user to create a Key with an ExpiredAt in time.Time +// and transform the Key structure into a KeyParsed structure to send the time format +// managed by Meilisearch +func convertKeyToParsedKey(key Key) (resp KeyParsed) { + resp = KeyParsed{Description: key.Description, Actions: key.Actions, Indexes: key.Indexes} + + // Convert time.Time to *string to feat the exact ISO-8601 + // format of Meilisearch + if !key.ExpiresAt.IsZero() { + const Format = "2006-01-02T15:04:05" + timeParsedToString := key.ExpiresAt.Format(Format) + resp.ExpiresAt = &timeParsedToString + } + return resp +} diff --git a/client_test.go b/client_test.go index e563dd7b..dcc9333a 100644 --- a/client_test.go +++ b/client_test.go @@ -81,6 +81,34 @@ func TestClient_GetAllStats(t *testing.T) { } } +func TestClient_GetKey(t *testing.T) { + tests := []struct { + name string + client *Client + }{ + { + name: "TestGetKey", + client: defaultClient, + }, + { + name: "TestGetKeyWithCustomClient", + client: customClient, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotResp, err := tt.client.GetKeys() + require.NoError(t, err) + + gotKey, err := tt.client.GetKey(gotResp.Results[0].Key) + require.NoError(t, err) + require.NotNil(t, gotKey.ExpiresAt) + require.NotNil(t, gotKey.CreatedAt) + require.NotNil(t, gotKey.UpdatedAt) + }) + } +} + func TestClient_GetKeys(t *testing.T) { tests := []struct { name string @@ -92,14 +120,321 @@ func TestClient_GetKeys(t *testing.T) { }, { name: "TestGetKeysWithCustomClient", - client: defaultClient, + client: customClient, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { gotResp, err := tt.client.GetKeys() + require.NoError(t, err) require.NotNil(t, gotResp, "GetKeys() should not return nil value") + require.GreaterOrEqual(t, len(gotResp.Results), 2) + }) + } +} + +func TestClient_CreateKey(t *testing.T) { + tests := []struct { + name string + client *Client + key Key + }{ + { + name: "TestCreateBasicKey", + client: defaultClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestCreateKeyWithCustomClient", + client: customClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestCreateKeyWithExpirationAt", + client: defaultClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + { + name: "TestCreateKeyWithDescription", + client: defaultClient, + key: Key{ + Description: "TestCreateKeyWithDescription", + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestCreateKeyWithActions", + client: defaultClient, + key: Key{ + Description: "TestCreateKeyWithActions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestCreateKeyWithIndexes", + client: defaultClient, + key: Key{ + Description: "TestCreateKeyWithIndexes", + Actions: []string{"*"}, + Indexes: []string{"movies", "games"}, + }, + }, + { + name: "TestCreateKeyWithAllOptions", + client: defaultClient, + key: Key{ + Description: "TestCreateKeyWithAllOptions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"movies", "games"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + const Format = "2006-01-02T15:04:05" + c := tt.client + t.Cleanup(cleanup(c)) + + gotResp, err := c.CreateKey(&tt.key) + require.NoError(t, err) + + gotKey, err := c.GetKey(gotResp.Key) + require.NoError(t, err) + require.Equal(t, tt.key.Description, gotKey.Description) + require.Equal(t, tt.key.Actions, gotKey.Actions) + require.Equal(t, tt.key.Indexes, gotKey.Indexes) + if !tt.key.ExpiresAt.IsZero() { + require.Equal(t, tt.key.ExpiresAt.Format(Format), gotKey.ExpiresAt.Format(Format)) + } + }) + } +} + +func TestClient_UpdateKey(t *testing.T) { + tests := []struct { + name string + client *Client + keyToCreate Key + keyToUpdate Key + }{ + { + name: "TestUpdateKeyWithDescription", + client: defaultClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Description: "TestUpdateKeyWithDescription", + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestUpdateKeyWithCustomClientWithDescription", + client: customClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Description: "TestUpdateKeyWithCustomClientWithDescription", + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestUpdateKeyWithExpirationAt", + client: defaultClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + { + name: "TestUpdateKeyWithActions", + client: defaultClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Description: "TestUpdateKeyWithActions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestUpdateKeyWithIndexes", + client: defaultClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Description: "TestUpdateKeyWithIndexes", + Actions: []string{"*"}, + Indexes: []string{"movies", "games"}, + }, + }, + { + name: "TestUpdateKeyWithAllOptions", + client: defaultClient, + keyToCreate: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + keyToUpdate: Key{ + Description: "TestUpdateKeyWithAllOptions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"movies", "games"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + const Format = "2006-01-02T15:04:05" + c := tt.client + t.Cleanup(cleanup(c)) + + gotResp, err := c.CreateKey(&tt.keyToCreate) + require.NoError(t, err) + + if tt.keyToCreate.Description != "" { + require.Equal(t, tt.keyToCreate.Description, gotResp.Description) + } + if len(tt.keyToCreate.Actions) != 0 { + require.Equal(t, tt.keyToCreate.Actions, gotResp.Actions) + } + if len(tt.keyToCreate.Indexes) != 0 { + require.Equal(t, tt.keyToCreate.Indexes, gotResp.Indexes) + } + if !tt.keyToCreate.ExpiresAt.IsZero() { + require.Equal(t, tt.keyToCreate.ExpiresAt.Format(Format), gotResp.ExpiresAt.Format(Format)) + } + + gotKey, err := c.UpdateKey(gotResp.Key, &tt.keyToUpdate) + require.NoError(t, err) + + if tt.keyToUpdate.Description != "" { + require.Equal(t, tt.keyToUpdate.Description, gotKey.Description) + } + if len(tt.keyToUpdate.Actions) != 0 { + require.Equal(t, tt.keyToUpdate.Actions, gotKey.Actions) + } + if len(tt.keyToUpdate.Indexes) != 0 { + require.Equal(t, tt.keyToUpdate.Indexes, gotKey.Indexes) + } + if !tt.keyToUpdate.ExpiresAt.IsZero() { + require.Equal(t, tt.keyToUpdate.ExpiresAt.Format(Format), gotKey.ExpiresAt.Format(Format)) + } + }) + } +} + +func TestClient_DeleteKey(t *testing.T) { + tests := []struct { + name string + client *Client + key Key + }{ + { + name: "TestDeleteBasicKey", + client: defaultClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestDeleteKeyWithCustomClient", + client: customClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestDeleteKeyWithExpirationAt", + client: defaultClient, + key: Key{ + Actions: []string{"*"}, + Indexes: []string{"*"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + { + name: "TestDeleteKeyWithDescription", + client: defaultClient, + key: Key{ + Description: "TestDeleteKeyWithDescription", + Actions: []string{"*"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestDeleteKeyWithActions", + client: defaultClient, + key: Key{ + Description: "TestDeleteKeyWithActions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"*"}, + }, + }, + { + name: "TestDeleteKeyWithIndexes", + client: defaultClient, + key: Key{ + Description: "TestDeleteKeyWithIndexes", + Actions: []string{"*"}, + Indexes: []string{"movies", "games"}, + }, + }, + { + name: "TestDeleteKeyWithAllOptions", + client: defaultClient, + key: Key{ + Description: "TestDeleteKeyWithAllOptions", + Actions: []string{"documents.add", "documents.delete"}, + Indexes: []string{"movies", "games"}, + ExpiresAt: time.Now().Add(time.Hour * 10), + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + c := tt.client + + gotKey, err := c.CreateKey(&tt.key) + require.NoError(t, err) + + gotResp, err := c.DeleteKey(gotKey.Key) + require.NoError(t, err) + require.True(t, gotResp) + + gotResp, err = c.DeleteKey(gotKey.Key) + require.Error(t, err) + require.False(t, gotResp) }) } } @@ -400,8 +735,8 @@ func TestClient_DefaultWaitForTask(t *testing.T) { { name: "TestDefaultWaitForTask", args: args{ - UID: "TestDefaultWaitForTask", - client: defaultClient, + UID: "TestDefaultWaitForTask", + client: defaultClient, taskID: &Task{ UID: 0, }, @@ -416,8 +751,8 @@ func TestClient_DefaultWaitForTask(t *testing.T) { { name: "TestDefaultWaitForTaskWithCustomClient", args: args{ - UID: "TestDefaultWaitForTaskWithCustomClient", - client: customClient, + UID: "TestDefaultWaitForTaskWithCustomClient", + client: customClient, taskID: &Task{ UID: 0, }, @@ -445,7 +780,6 @@ func TestClient_DefaultWaitForTask(t *testing.T) { } } - func TestClient_WaitForTaskWithContext(t *testing.T) { type args struct { UID string diff --git a/main_test.go b/main_test.go index 018cc261..ff969f93 100644 --- a/main_test.go +++ b/main_test.go @@ -4,6 +4,7 @@ import ( "crypto/tls" "fmt" "os" + "strings" "testing" "github.com/stretchr/testify/require" @@ -39,9 +40,28 @@ func deleteAllIndexes(client ClientInterface) (ok bool, err error) { return true, nil } +func deleteAllKeys(client ClientInterface) (ok bool, err error) { + list, err := client.GetKeys() + if err != nil { + return false, err + } + + for _, key := range list.Results { + if strings.Contains(key.Description, "Test") || (key.Description == "") { + _, err = client.DeleteKey(key.Key) + if err != nil { + return false, err + } + } + } + + return true, nil +} + func cleanup(c ClientInterface) func() { return func() { _, _ = deleteAllIndexes(c) + _, _ = deleteAllKeys(c) } } diff --git a/types.go b/types.go index 7663c060..f7ffa261 100644 --- a/types.go +++ b/types.go @@ -96,9 +96,29 @@ type ResultTask struct { // Keys allow the user to connect to the MeiliSearch instance // // Documentation: https://docs.meilisearch.com/learn/advanced/security.html#protecting-a-meilisearch-instance -type Keys struct { - Public string `json:"public,omitempty"` - Private string `json:"private,omitempty"` +type Key struct { + Description string `json:"description"` + Key string `json:"key,omitempty"` + Actions []string `json:"actions,omitempty"` + Indexes []string `json:"indexes,omitempty"` + CreatedAt time.Time `json:"createdAt,omitempty"` + UpdatedAt time.Time `json:"updatedAt,omitempty"` + ExpiresAt time.Time `json:"expiresAt"` +} + +// This structure is used to send the exact ISO-8601 time format managed by Meilisearch +type KeyParsed struct { + Description string `json:"description"` + Key string `json:"key,omitempty"` + Actions []string `json:"actions,omitempty"` + Indexes []string `json:"indexes,omitempty"` + CreatedAt time.Time `json:"createdAt,omitempty"` + UpdatedAt time.Time `json:"updatedAt,omitempty"` + ExpiresAt *string `json:"expiresAt"` +} + +type ResultKey struct { + Results []Key `json:"results"` } // DumpStatus is the status of a dump. diff --git a/types_easyjson.go b/types_easyjson.go index 39942c5b..639ca44c 100644 --- a/types_easyjson.go +++ b/types_easyjson.go @@ -1575,7 +1575,7 @@ func (v *ResultTask) UnmarshalJSON(data []byte) error { func (v *ResultTask) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo9(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(in *jlexer.Lexer, out *Keys) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(in *jlexer.Lexer, out *ResultKey) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1594,10 +1594,29 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(in *jlexer.Lexer, continue } switch key { - case "public": - out.Public = string(in.String()) - case "private": - out.Private = string(in.String()) + case "results": + if in.IsNull() { + in.Skip() + out.Results = nil + } else { + in.Delim('[') + if out.Results == nil { + if !in.IsDelim(']') { + out.Results = make([]Key, 0, 0) + } else { + out.Results = []Key{} + } + } else { + out.Results = (out.Results)[:0] + } + for !in.IsDelim(']') { + var v49 Key + (v49).UnmarshalEasyJSON(in) + out.Results = append(out.Results, v49) + in.WantComma() + } + in.Delim(']') + } default: in.SkipRecursive() } @@ -1608,53 +1627,411 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo10(out *jwriter.Writer, in Keys) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo10(out *jwriter.Writer, in ResultKey) { out.RawByte('{') first := true _ = first - if in.Public != "" { - const prefix string = ",\"public\":" - first = false + { + const prefix string = ",\"results\":" out.RawString(prefix[1:]) - out.String(string(in.Public)) - } - if in.Private != "" { - const prefix string = ",\"private\":" - if first { - first = false - out.RawString(prefix[1:]) + if in.Results == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") } else { - out.RawString(prefix) + out.RawByte('[') + for v50, v51 := range in.Results { + if v50 > 0 { + out.RawByte(',') + } + (v51).MarshalEasyJSON(out) + } + out.RawByte(']') } - out.String(string(in.Private)) } out.RawByte('}') } // MarshalJSON supports json.Marshaler interface -func (v Keys) MarshalJSON() ([]byte, error) { +func (v ResultKey) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo10(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface -func (v Keys) MarshalEasyJSON(w *jwriter.Writer) { +func (v ResultKey) MarshalEasyJSON(w *jwriter.Writer) { easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo10(w, v) } // UnmarshalJSON supports json.Unmarshaler interface -func (v *Keys) UnmarshalJSON(data []byte) error { +func (v *ResultKey) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *Keys) UnmarshalEasyJSON(l *jlexer.Lexer) { +func (v *ResultKey) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo10(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(in *jlexer.Lexer, out *Index) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(in *jlexer.Lexer, out *KeyParsed) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "description": + out.Description = string(in.String()) + case "key": + out.Key = string(in.String()) + case "actions": + if in.IsNull() { + in.Skip() + out.Actions = nil + } else { + in.Delim('[') + if out.Actions == nil { + if !in.IsDelim(']') { + out.Actions = make([]string, 0, 4) + } else { + out.Actions = []string{} + } + } else { + out.Actions = (out.Actions)[:0] + } + for !in.IsDelim(']') { + var v52 string + v52 = string(in.String()) + out.Actions = append(out.Actions, v52) + in.WantComma() + } + in.Delim(']') + } + case "indexes": + if in.IsNull() { + in.Skip() + out.Indexes = nil + } else { + in.Delim('[') + if out.Indexes == nil { + if !in.IsDelim(']') { + out.Indexes = make([]string, 0, 4) + } else { + out.Indexes = []string{} + } + } else { + out.Indexes = (out.Indexes)[:0] + } + for !in.IsDelim(']') { + var v53 string + v53 = string(in.String()) + out.Indexes = append(out.Indexes, v53) + in.WantComma() + } + in.Delim(']') + } + case "createdAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.CreatedAt).UnmarshalJSON(data)) + } + case "updatedAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.UpdatedAt).UnmarshalJSON(data)) + } + case "expiresAt": + if in.IsNull() { + in.Skip() + out.ExpiresAt = nil + } else { + if out.ExpiresAt == nil { + out.ExpiresAt = new(string) + } + *out.ExpiresAt = string(in.String()) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(out *jwriter.Writer, in KeyParsed) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"description\":" + out.RawString(prefix[1:]) + out.String(string(in.Description)) + } + if in.Key != "" { + const prefix string = ",\"key\":" + out.RawString(prefix) + out.String(string(in.Key)) + } + if len(in.Actions) != 0 { + const prefix string = ",\"actions\":" + out.RawString(prefix) + { + out.RawByte('[') + for v54, v55 := range in.Actions { + if v54 > 0 { + out.RawByte(',') + } + out.String(string(v55)) + } + out.RawByte(']') + } + } + if len(in.Indexes) != 0 { + const prefix string = ",\"indexes\":" + out.RawString(prefix) + { + out.RawByte('[') + for v56, v57 := range in.Indexes { + if v56 > 0 { + out.RawByte(',') + } + out.String(string(v57)) + } + out.RawByte(']') + } + } + if true { + const prefix string = ",\"createdAt\":" + out.RawString(prefix) + out.Raw((in.CreatedAt).MarshalJSON()) + } + if true { + const prefix string = ",\"updatedAt\":" + out.RawString(prefix) + out.Raw((in.UpdatedAt).MarshalJSON()) + } + { + const prefix string = ",\"expiresAt\":" + out.RawString(prefix) + if in.ExpiresAt == nil { + out.RawString("null") + } else { + out.String(string(*in.ExpiresAt)) + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v KeyParsed) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v KeyParsed) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *KeyParsed) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *KeyParsed) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(l, v) +} +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(in *jlexer.Lexer, out *Key) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "description": + out.Description = string(in.String()) + case "key": + out.Key = string(in.String()) + case "actions": + if in.IsNull() { + in.Skip() + out.Actions = nil + } else { + in.Delim('[') + if out.Actions == nil { + if !in.IsDelim(']') { + out.Actions = make([]string, 0, 4) + } else { + out.Actions = []string{} + } + } else { + out.Actions = (out.Actions)[:0] + } + for !in.IsDelim(']') { + var v58 string + v58 = string(in.String()) + out.Actions = append(out.Actions, v58) + in.WantComma() + } + in.Delim(']') + } + case "indexes": + if in.IsNull() { + in.Skip() + out.Indexes = nil + } else { + in.Delim('[') + if out.Indexes == nil { + if !in.IsDelim(']') { + out.Indexes = make([]string, 0, 4) + } else { + out.Indexes = []string{} + } + } else { + out.Indexes = (out.Indexes)[:0] + } + for !in.IsDelim(']') { + var v59 string + v59 = string(in.String()) + out.Indexes = append(out.Indexes, v59) + in.WantComma() + } + in.Delim(']') + } + case "createdAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.CreatedAt).UnmarshalJSON(data)) + } + case "updatedAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.UpdatedAt).UnmarshalJSON(data)) + } + case "expiresAt": + if data := in.Raw(); in.Ok() { + in.AddError((out.ExpiresAt).UnmarshalJSON(data)) + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(out *jwriter.Writer, in Key) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"description\":" + out.RawString(prefix[1:]) + out.String(string(in.Description)) + } + if in.Key != "" { + const prefix string = ",\"key\":" + out.RawString(prefix) + out.String(string(in.Key)) + } + if len(in.Actions) != 0 { + const prefix string = ",\"actions\":" + out.RawString(prefix) + { + out.RawByte('[') + for v60, v61 := range in.Actions { + if v60 > 0 { + out.RawByte(',') + } + out.String(string(v61)) + } + out.RawByte(']') + } + } + if len(in.Indexes) != 0 { + const prefix string = ",\"indexes\":" + out.RawString(prefix) + { + out.RawByte('[') + for v62, v63 := range in.Indexes { + if v62 > 0 { + out.RawByte(',') + } + out.String(string(v63)) + } + out.RawByte(']') + } + } + if true { + const prefix string = ",\"createdAt\":" + out.RawString(prefix) + out.Raw((in.CreatedAt).MarshalJSON()) + } + if true { + const prefix string = ",\"updatedAt\":" + out.RawString(prefix) + out.Raw((in.UpdatedAt).MarshalJSON()) + } + { + const prefix string = ",\"expiresAt\":" + out.RawString(prefix) + out.Raw((in.ExpiresAt).MarshalJSON()) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Key) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Key) MarshalEasyJSON(w *jwriter.Writer) { + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Key) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Key) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(l, v) +} +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(in *jlexer.Lexer, out *Index) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1695,7 +2072,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(out *jwriter.Writer, in Index) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(out *jwriter.Writer, in Index) { out.RawByte('{') first := true _ = first @@ -1725,27 +2102,27 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v Index) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Index) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo11(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Index) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Index) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo11(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(in *jlexer.Lexer, out *Health) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(in *jlexer.Lexer, out *Health) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1776,7 +2153,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(out *jwriter.Writer, in Health) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(out *jwriter.Writer, in Health) { out.RawByte('{') first := true _ = first @@ -1791,27 +2168,27 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v Health) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Health) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo12(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Health) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Health) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo12(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(in *jlexer.Lexer, out *Dump) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(in *jlexer.Lexer, out *Dump) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1852,7 +2229,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(out *jwriter.Writer, in Dump) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(out *jwriter.Writer, in Dump) { out.RawByte('{') first := true _ = first @@ -1882,27 +2259,27 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v Dump) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Dump) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo13(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Dump) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Dump) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo13(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(in *jlexer.Lexer, out *DocumentsRequest) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(in *jlexer.Lexer, out *DocumentsRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1941,9 +2318,9 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(in *jlexer.Lexer, out.AttributesToRetrieve = (out.AttributesToRetrieve)[:0] } for !in.IsDelim(']') { - var v49 string - v49 = string(in.String()) - out.AttributesToRetrieve = append(out.AttributesToRetrieve, v49) + var v64 string + v64 = string(in.String()) + out.AttributesToRetrieve = append(out.AttributesToRetrieve, v64) in.WantComma() } in.Delim(']') @@ -1958,7 +2335,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(out *jwriter.Writer, in DocumentsRequest) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(out *jwriter.Writer, in DocumentsRequest) { out.RawByte('{') first := true _ = first @@ -1988,11 +2365,11 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(out *jwriter.Writ } { out.RawByte('[') - for v50, v51 := range in.AttributesToRetrieve { - if v50 > 0 { + for v65, v66 := range in.AttributesToRetrieve { + if v65 > 0 { out.RawByte(',') } - out.String(string(v51)) + out.String(string(v66)) } out.RawByte(']') } @@ -2003,27 +2380,27 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v DocumentsRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v DocumentsRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo14(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *DocumentsRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *DocumentsRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo14(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(in *jlexer.Lexer, out *CreateIndexRequest) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo17(in *jlexer.Lexer, out *CreateIndexRequest) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2056,7 +2433,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(out *jwriter.Writer, in CreateIndexRequest) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo17(out *jwriter.Writer, in CreateIndexRequest) { out.RawByte('{') first := true _ = first @@ -2082,27 +2459,27 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v CreateIndexRequest) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo17(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v CreateIndexRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo15(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo17(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *CreateIndexRequest) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo17(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *CreateIndexRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo15(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo17(l, v) } -func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(in *jlexer.Lexer, out *Client) { +func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo18(in *jlexer.Lexer, out *Client) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -2131,7 +2508,7 @@ func easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(in *jlexer.Lexer, in.Consumed() } } -func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(out *jwriter.Writer, in Client) { +func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo18(out *jwriter.Writer, in Client) { out.RawByte('{') first := true _ = first @@ -2141,23 +2518,23 @@ func easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(out *jwriter.Writ // MarshalJSON supports json.Marshaler interface func (v Client) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(&w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo18(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Client) MarshalEasyJSON(w *jwriter.Writer) { - easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo16(w, v) + easyjson6601e8cdEncodeGithubComMeilisearchMeilisearchGo18(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Client) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(&r, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo18(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Client) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo16(l, v) + easyjson6601e8cdDecodeGithubComMeilisearchMeilisearchGo18(l, v) }