apollo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2023 License: MIT Imports: 10 Imported by: 0

README

Apollo config centry

This module implements the config.Source interface in kratos based apollo config management center.

go.dev reference

Quick start

import (
	"fmt"
	"log"

	"github.com/go-kratos/kratos/contrib/config/apollo/v2"
	"github.com/limes-cloud/kratos/config"
)

func main() {
	c := config.New(
		config.WithSource(
			apollo.NewSource(
				apollo.WithAppID("kratos"),
				apollo.WithCluster("dev"),
				apollo.WithEndpoint("http://localhost:8080"),
				apollo.WithNamespace("application,event.yaml,demo.json"),
				apollo.WithEnableBackup(),
				apollo.WithSecret("ad75b33c77ae4b9c9626d969c44f41ee"),
			),
		),
	)
	var bc bootstrap
	if err := c.Load(); err != nil {
		panic(err)
	}
	
	// use value and watch operations,help yourself. 
}

Options list

You get what you see.

// specify the app id
func WithAppID(appID string) Option
// specify the cluster of application
func WithCluster(cluster string) Option

// enable backup or not, and where to back up them.
func WithBackupPath(backupPath string) Option
func WithDisableBackup() Option
func WithEnableBackup() Option

// specify apollo endpoint, such as http://localhost:8080
func WithEndpoint(endpoint string) Option

// namespaces to load, comma to separate. 
func WithNamespace(name string) Option

// secret is the apollo secret key to access application config.
func WithSecret(secret string) Option

Notice

apollo config center use Namespace to be part of the key. For example:

application.json

{
  "http": {
    "address": ":8080",
    "tls": {
      "enable": false,
      "cert_file": "",
      "key_file": ""
    }
  }
}

you got them in kratos config instance maybe look like:

config := map[string]interface{}{
	// application be part of the key path.
	"application": map[string]interface{}{
        "http": map[string]interface{}{
            "address": ":8080",
            "tls": map[string]interface{}{
                "enable": false,
                "cert_file": "",
                "key_file": ""
            }
        }
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSource

func NewSource(opts ...Option) config.Source

Types

type Option

type Option func(*options)

Option is apollo option

func WithAppID

func WithAppID(appID string) Option

WithAppID with apollo config app id

func WithBackupPath

func WithBackupPath(backupPath string) Option

WithBackupPath with apollo config backupPath

func WithCluster

func WithCluster(cluster string) Option

WithCluster with apollo config cluster

func WithDisableBackup

func WithDisableBackup() Option

WithDisableBackup with apollo config enable backup config

func WithEnableBackup

func WithEnableBackup() Option

WithEnableBackup with apollo config enable backup config

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint with apollo config conf server ip

func WithNamespace

func WithNamespace(name string) Option

WithNamespace with apollo config namespace name

func WithOriginalConfig

func WithOriginalConfig() Option

WithOriginalConfig use the original configuration file without parse processing

func WithSecret

func WithSecret(secret string) Option

WithSecret with apollo config app secret

Jump to

Keyboard shortcuts

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