项目作者: deweppro

项目描述 :
Data migration
高级语言: Go
项目地址: git://github.com/deweppro/stagger.git
创建时间: 2020-09-10T15:27:59Z
项目社区:https://github.com/deweppro/stagger

开源协议:BSD 3-Clause "New" or "Revised" License

下载


stagger

codecov
Release
Go Report Card
Build Status

Consul migration

Example:

  1. package main
  2. import (
  3. "fmt"
  4. "github.com/deweppro/stagger/consul"
  5. )
  6. func main() {
  7. // Init migration client
  8. cli, err := consul.CreateConsulMigrate("consul:8500")
  9. if err != nil {
  10. panic(err)
  11. }
  12. // Get all existing keys from consul
  13. kvs, err := cli.Dump()
  14. if err != nil {
  15. panic(err)
  16. }
  17. for _, kv := range kvs {
  18. fmt.Println(kv.Key, kv.Type, kv.Value)
  19. }
  20. // Save all existing keys from consul to file
  21. err = cli.DumpToFile("/tml/dump.yaml")
  22. if err != nil {
  23. panic(err)
  24. }
  25. // Save keys to consul
  26. err = cli.Migrate(kvs)
  27. if err != nil {
  28. panic(err)
  29. }
  30. // Migration of keys from a file in the consul.
  31. err = cli.MigrateFromFile("/tmp/dump.yaml")
  32. if err != nil {
  33. panic(err)
  34. }
  35. // Scan directories, merge files with sort by name,
  36. // and the migration of keys from files in the consul.
  37. err = cli.MigrateFromDir("/tmp")
  38. if err != nil {
  39. panic(err)
  40. }
  41. }

Migration file format:

  1. - key: test # name
  2. value: '{"hello":"world"}' # value
  3. type: json # type (choice: base64, json)

Add Keys

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

  1. - key: test
  2. value: 123

JSON format: (with key value validation as json)

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

Base64 format: (with key value validation as base64)

  1. - key: test
  2. value: aGVsbG8gd29ybGQ=
  3. type: base64

Delete Keys

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

  1. - key: test