[Update] Add comment

This commit is contained in:
trunglt251292 2022-03-10 11:36:06 +07:00
parent 91598d848f
commit 0f04829163
4 changed files with 26 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package elasticsearch
import "github.com/Selly-Modules/natsio"
// Config int client elasticsearch
type Config struct {
ApiKey string
Nats natsio.Config

View File

@ -1,5 +1,5 @@
package elasticsearch
const SubjectSyncData = "sync_data"
const SubjectSearch = "search"
const SubjectUpdateDocument = "update_document"
const SubjectSyncData = "elasticsearch_sync_data"
const SubjectSearch = "elasticsearch_search"
const SubjectUpdateDocument = "elasticsearch_update_document"

View File

@ -8,12 +8,15 @@ import (
"github.com/Selly-Modules/natsio"
)
// Client ...
type Client struct {
Config Config
natsServer natsio.Server
natsJetStream natsio.JetStream
}
// NewClient
// Init client elasticsearch
func NewClient(config Config) (*Client, error) {
if config.ApiKey == "" {
return nil, errors.New("api key is required")
@ -34,6 +37,8 @@ func NewClient(config Config) (*Client, error) {
return c, nil
}
// SyncData
// Sync data to services ES
func (c *Client) SyncData(data SyncData) (bool, error) {
var (
res Response
@ -51,6 +56,8 @@ func (c *Client) SyncData(data SyncData) (bool, error) {
return res.Success, nil
}
// Search
// Request search to service es
func (c *Client) Search(query ESQuery) ([]string, error) {
var (
res Response
@ -68,6 +75,8 @@ func (c *Client) Search(query ESQuery) ([]string, error) {
return res.Data, nil
}
// UpdateDocument
// Insert or update document to ES
func (c *Client) UpdateDocument(query UpdateDataPayload) ([]string, error) {
var (
res Response

View File

@ -2,6 +2,8 @@ package elasticsearch
import "time"
// Response
// response to service es
type Response struct {
Success bool `json:"success"`
Data []string `json:"data,omitempty"`
@ -11,16 +13,22 @@ type Response struct {
Message string `json:"message"`
}
// SyncData
// Payload for sync data to service es
type SyncData struct {
Index string
Data []byte
}
// UpdateDataPayload
// Payload for insert or update document
type UpdateDataPayload struct {
Index string
Body []byte
}
// ESQuery
// Query support to search document
type ESQuery struct {
Index string // Index
Page int64
@ -73,7 +81,11 @@ type ESQuery struct {
Segments []string
}
// ESSort
// ES sort with field
// ... filed is sort
// ... ascending [true is asc] [false is desc]
type ESSort struct {
Filed string // Filed sort
Field string // Filed sort
Ascending bool
}