Data migration
Example:
package mainimport ("fmt""github.com/deweppro/stagger/consul")func main() {// Init migration clientcli, err := consul.CreateConsulMigrate("consul:8500")if err != nil {panic(err)}// Get all existing keys from consulkvs, 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 fileerr = cli.DumpToFile("/tml/dump.yaml")if err != nil {panic(err)}// Save keys to consulerr = 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 # namevalue: '{"hello":"world"}' # valuetype: json # type (choice: base64, json)
Default format: (without specifying the key type to disable value validation)
- key: testvalue: 123
JSON format: (with key value validation as json)
- key: testvalue: '[1,2,3,4]'type: json
Base64 format: (with key value validation as base64)
- key: testvalue: aGVsbG8gd29ybGQ=type: base64
For delete a key from the consul, remove the parameter with the key value in the migration file.
- key: test