es

package
v0.1.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"github.com/sqjian/go-kit/es"
	"github.com/sqjian/go-kit/net/http"
	"log"
	"strings"
)

func main() {
	checkErr := func(err error) {
		if err != nil {
			panic(err)
		}
	}

	const (
		esAddr  = `https://x.x.x.x:xxxx`
		esIndex = `go-kit`
	)

	var (
		ctx = context.Background()
	)

	cli, esCLiErr := es.NewEsCli(
		es.WithHosts(esAddr),
		es.WithDebugInfo(true),
		es.WithHttpClient(http.GetDefaultHttpClient()),
	)
	checkErr(esCLiErr)

	{
		exists, err := cli.IndexExists(ctx, esIndex)
		checkErr(err)
		if !exists {
			err := cli.CreateIndex(ctx, esIndex)
			checkErr(err)
		}
	}
	{
		err := cli.WriteDocs(
			ctx,
			esIndex,
			map[string]any{
				"name": "sqjian",
				"age":  18,
			},
		)
		checkErr(err)
	}
	{
		rst, err := cli.QueryDocs(
			ctx,
			esIndex,
			map[string]any{
				"name": "sqjian",
				"age":  18,
			},
		)
		checkErr(err)
		log.Printf("rst:%v", strings.Join(rst, "\n"))
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrWrapper

func ErrWrapper(err Err) error

func NewEsCli added in v0.0.51

func NewEsCli(opts ...OptionFunc) (*cli, error)

Types

type Err

type Err int
const (
	UnknownErrCode Err = iota
	IllegalParams      // wrong params
)

func (Err) String

func (i Err) String() string

type OptionFunc added in v0.0.46

type OptionFunc func(*cli)

func WithDebugInfo

func WithDebugInfo(debug bool) OptionFunc

func WithHosts

func WithHosts(hosts ...string) OptionFunc

func WithHttpClient

func WithHttpClient(httpCli *http.Client) OptionFunc

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL