stagger

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2020 License: BSD-3-Clause

README

stagger

Release Go Report Card Build Status

Consul migration

Example:

package main

import (
	"fmt"

	"github.com/deweppro/stagger/consul"
)

func main() {

	// Init migration client
	cli, err := consul.CreateConsulMigrate("consul:8500")
	if err != nil {
		panic(err)
	}

	// Get all existing keys from consul
	kvs, err := cli.Dump()
	if err != nil {
		panic(err)
	}
	for _, kv := range kvs {
		fmt.Println(kv.Key, kv.Type, kv.Value)
	}

	// Save all existing keys from consul to file
	err = cli.DumpToFile("/tml/dump.yaml")
	if err != nil {
		panic(err)
	}

	// Save keys to consul
	err = cli.Migrate(kvs)
	if err != nil {
		panic(err)
	}

	// Migration of keys from a file in the consul.
	err = cli.MigrateFromFile("/tmp/dump.yaml")
	if err != nil {
		panic(err)
	}

	// Scan directories, merge files with sort by name,
	// and the migration of keys from files in the consul.
	err = cli.MigrateFromDir("/tmp")
	if err != nil {
		panic(err)
	}

}

Migration file format:

- key: test                   # name
  value: '{"hello":"world"}'  # value
  type: json                  # type (choice: base64, json)
Add Keys

Default format: (without specifying the key type to disable value validation)

- key: test  
  value: 123

JSON format: (with key value validation as json)

- key: test  
  value: '[1,2,3,4]'
  type: json

Base64 format: (with key value validation as base64)

- key: test  
  value: aGVsbG8gd29ybGQ=
  type: base64
Delete Keys

For delete a key from the consul, remove the parameter with the key value in the migration file.

- key: test

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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