elasticsearch

package module
v0.0.1-3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 2 Imported by: 0

README

Pip.Services Logo
ElasticSearch components for PipServices in Go

This module is a part of the Pip.Services polyglot microservices toolkit.

The Elasticsearch module contains logging components with data storage on the Elasticsearch server.

The module contains the following packages:

  • Build - contains a factory for the construction of components
  • Log - Logging components

Quick links:

Use

Get the package from the Github repository:

go get -u github.com/pip-services4/pip-services4-go/pip-services4-elasticsearch-go@latest

Microservice components shall perform logging usual way using CompositeLogger component. The CompositeLogger will get ElasticSearchLogger from references and will redirect log messages there among other destinations.

import (
	"context"

	"github.com/pip-services4/pip-services4-go/pip-services4-components-go/config"
	"github.com/pip-services4/pip-services4-go/pip-services4-components-go/refer"
	"github.com/pip-services4/pip-services4-go/pip-services4-observability-go/log"
)

type MyComponent struct {
	logger *log.CompositeLogger
}

func (c *MyComponent) Configure(ctx context.Context, config *config.ConfigParams) {
	c.logger.Configure(ctx, config)
}
func (c *MyComponent) SetReferences(ctx context.Context, references refer.IReferences) {
	c.logger.SetReferences(ctx, references)
}

func (c *MyComponent) MyMethod(ctx context.Context, param1 any) (any, error) {
	c.logger.Trace(ctx, "Executed method mycomponent.mymethod")
	// ....
}

Configuration for your microservice that includes ElasticSearch logger may look the following way.

...
{{#if ELASTICSEARCH_ENABLED}}
- descriptor: pip-services:logger:elasticsearch:default:1.0
  connection:
    uri: {{{ELASTICSEARCG_SERVICE_URI}}}
    host: {{{ELASTICSEARCH_SERVICE_HOST}}}{{#unless ELASTICSEARCH_SERVICE_HOST}}localhost{{/unless}}
    port: {{ELASTICSEARCG_SERVICE_PORT}}{{#unless ELASTICSEARCH_SERVICE_PORT}}9200{{/unless}}\ 
{{/if}}
...

Develop

For development you shall install the following prerequisites:

  • Golang v1.20+
  • Visual Studio Code or another IDE of your choice
  • Docker
  • Git

Run automated tests:

go test -v ./test/...

Generate API documentation:

./docgen.ps1

Before committing changes run dockerized test as:

./test.ps1
./clear.ps1

Contacts

The library is created and maintained by Sergey Seroukhov and Levichev Dmitry.

The documentation is written by:

  • Levichev Dmitry

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
test
log

Jump to

Keyboard shortcuts

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