-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 792 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"backup-db/mysql"
"github.com/spf13/viper"
"log"
"sync"
)
func main() {
log.Println("Beginning DB backup script")
ch := make(chan string)
// Non-blocking goroutine. Blocking would be ok here but this is for practice
go func() {
wg := sync.WaitGroup{}
for _, val := range mysql.C {
wg.Add(1)
go mysql.DumpDB(val, ch, &wg)
}
wg.Wait()
close(ch)
}()
for val := range ch {
log.Println("Output: ", val)
}
}
func init() {
viper.AddConfigPath("./setup")
viper.SetConfigName("config") // Register config file name (no extension)
viper.SetConfigType("json") // Look for specific type
err := viper.ReadInConfig()
if err != nil {
panic(err)
}
err = viper.UnmarshalKey("databases", &mysql.C)
if err != nil {
log.Fatal(err)
}
}