Skip to content

Change the usage #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks
alallema opened this issue May 26, 2021 · 0 comments · Fixed by #150
Closed
4 tasks

Change the usage #148

alallema opened this issue May 26, 2021 · 0 comments · Fixed by #150
Assignees
Labels
breaking-change The related changes are breaking for the users

Comments

@alallema
Copy link
Contributor

alallema commented May 26, 2021

Description

In the continuity of this discussion. The Meilisearch Teams has decided to try to bring documentation, logic, and structure of this SDK closer to the others to be more developer-friendly and to have a usage that seems to us more pleasant and more accessible.

Steps

Changing the usage

package main

import (
	"fmt"

	"github.com/meilisearch/meilisearch-go"
	"github.com/meilisearch/meilisearch-go/client"
)
func main() {
	client = meilisearch.NewClient(client.ClientConfig{
                Host: "http://127.0.0.1:7700",
                MasterKey: "masterKey",
        })
	// An index is where the documents are stored.
	index := client.Index("indexUID")

	// If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
	documents := []map[string]interface{}{
		{"book_id": 123,  "title": "Pride and Prejudice"},
		{"book_id": 456,  "title": "Le Petit Prince"},
		{"book_id": 1,    "title": "Alice In Wonderland"},
		{"book_id": 1344, "title": "The Hobbit"},
		{"book_id": 4,    "title": "Harry Potter and the Half-Blood Prince"},
		{"book_id": 42,   "title": "The Hitchhiker's Guide to the Galaxy"},
	}
	_, err := index.addDocuments(documents)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	index.Delete()
}

Restructure the file hierarchies

New package structure inspired by what stripe does and following @eskombro guidance:

  • A Client package, which is responsible for:

    • Index creation, update, and retrieval
    • Global MeiliSearch keys handling
    • Server stats, health, sys-info, and version
  • An Index package, responsible for:

    • Documents
    • Updates
    • Search (internal to each index)
    • Index settings
    • Index stats
  • A Custom Error package widely used in the project following previous error handling discussions

    • which will be made in a next issue

Tests

All methods must be well tested a lot

To do

  • Client package
  • Index package
  • Error package
  • Tests
@curquiza curquiza changed the title SDK Refactor Change the usage May 26, 2021
@curquiza curquiza added the breaking-change The related changes are breaking for the users label May 26, 2021
@alallema alallema linked a pull request Jun 1, 2021 that will close this issue
11 tasks
@bors bors bot closed this as completed in #150 Jun 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants