Skip to content

Commit

Permalink
Make indexID configurable (#2)
Browse files Browse the repository at this point in the history
* Make indexID configurable

* Fix sprintf parameter order

* Make indexID a mandatory parameter instead of having a default value

---------

Co-authored-by: Lukas Knienieder <[email protected]>
  • Loading branch information
blaargh and Lukas Knienieder authored Jun 4, 2024
1 parent 08ae5ab commit 2c5ad1b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func New(cfg Config) *Client {
panic("missing Quickwit URL")
}

if cfg.IndexID == "" {
panic("missing Quickwit Index ID")
}

if cfg.BatchWait < 0 {
panic("wrong BatchWait option")
}
Expand Down Expand Up @@ -56,8 +60,8 @@ func New(cfg Config) *Client {
}

// NewWithDefault creates a new client with default configuration.
func NewWithDefault(url string) *Client {
return New(NewDefaultConfig(url))
func NewWithDefault(url string, indexID string) *Client {
return New(NewDefaultConfig(url, indexID))
}

func (c *Client) run() {
Expand Down Expand Up @@ -130,7 +134,7 @@ func (c *Client) send(buf *bytes.Buffer) (int, error) {
ctx, cancel := context.WithTimeout(context.Background(), c.cfg.Timeout)
defer cancel()

url := c.cfg.URL + "/api/v1/test/ingest?commit=" + string(c.cfg.Commit)
url := fmt.Sprintf("%s/api/v1/%s/ingest?commit=%s", c.cfg.URL, c.cfg.IndexID, string(c.cfg.Commit))

req, err := http.NewRequestWithContext(ctx, "POST", url, buf)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type Config struct {
URL string
Client http.Client

IndexID string

BatchWait time.Duration
BatchBytes int
Commit CommitMode
Expand All @@ -39,11 +41,13 @@ type Config struct {
}

// NewDefaultConfig creates a default configuration for a given Quickwit cluster.
func NewDefaultConfig(url string) Config {
func NewDefaultConfig(url string, indexID string) Config {
return Config{
URL: url,
Client: http.Client{},

IndexID: indexID,

BatchWait: DefaultBatchWait,
BatchBytes: DefaultBatchBytes,
Commit: DefautCommitMode,
Expand Down
2 changes: 1 addition & 1 deletion example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
// -H 'Content-Type: application/yaml' \
// --data-binary @test-config.yaml

client := quickwit.NewWithDefault("http://localhost:7280")
client := quickwit.NewWithDefault("http://localhost:7280", "test")
defer client.Stop() // flush and stop

for i := 0; i < 10; i++ {
Expand Down

0 comments on commit 2c5ad1b

Please sign in to comment.