Skip to content

Latest commit

 

History

History
71 lines (51 loc) · 2.57 KB

README.md

File metadata and controls

71 lines (51 loc) · 2.57 KB

OpenSergo Logo

OpenSergo Go SDK

OpenSergo Go SDK CI License

Introduction

Documentation

See the OpenSergo Website for the official website of OpenSergo.

See the 中文文档 for document in Chinese.

Quick Start

func StartAndSubscribeOpenSergoConfig() error {
	// Set OpenSergo console logger (optional)
	logging.NewConsoleLogger(logging.InfoLevel, logging.SeparateFormat, true)
	// Set OpenSergo file logger (optional)
	// logging.NewFileLogger("./opensergo-universal-transport-service.log", logging.InfoLevel, logging.JsonFormat, true)

	// Create an OpenSergoClient.
	openSergoClient, err := client.NewOpenSergoClient("127.0.0.1", 10246)
	if err != nil {
		return err
	}

	// Start the OpenSergoClient.
	err = openSergoClient.Start()
	if err != nil {
		return err
	}

	// Create a SubscribeKey for FaultToleranceRule.
	faultToleranceSubscribeKey := model.NewSubscribeKey("default", "foo-app", configkind.ConfigKindRefFaultToleranceRule{})
	// Create a Subscriber.
	sampleFaultToleranceRuleSubscriber := &samples.SampleFaultToleranceRuleSubscriber{}
	// Subscribe data with the key and subscriber.
	err = openSergoClient.SubscribeConfig(*faultToleranceSubscribeKey, api.WithSubscriber(sampleFaultToleranceRuleSubscriber))
	if err != nil {
		return err
	}

	// Create a SubscribeKey for RateLimitStrategy.
	rateLimitSubscribeKey := model.NewSubscribeKey("default", "foo-app", configkind.ConfigKindRefRateLimitStrategy{})
	// Subscribe data with the key, but without a subscriber.
	// We may pull the data from the data cache later.
	err = openSergoClient.SubscribeConfig(*rateLimitSubscribeKey))

	return err
}

Samples

For more samples, please refer to here.

Components

logger mechanism

In OpenSergo Go SDK, we provide a fundamental logger mechanism, which has the following features:

  • provider a universal Logger interface. Users may register customized logger adapters.
  • provider a default Logger implementation, which can be used directory.
  • provider a default Logger format assembler, which can assemble two formatters of log message.

Detail info refers to pkg/common/logging