forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop.go
51 lines (44 loc) · 1013 Bytes
/
pop.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
49
50
51
package pop
import (
"fmt"
"log"
"os"
"github.com/fatih/color"
)
// AvailableDialects lists the available database dialects
var AvailableDialects = []string{"postgres", "mysql", "cockroach"}
// Debug mode, to toggle verbose log traces
var Debug = false
// Color mode, to toggle colored logs
var Color = true
var logger = log.New(os.Stdout, "[POP] ", log.LstdFlags)
// Log a formatted string to the logger
var Log = func(s string, args ...interface{}) {
if Debug {
if len(args) > 0 {
xargs := make([]string, len(args))
for i, a := range args {
switch a.(type) {
case string:
xargs[i] = fmt.Sprintf("%q", a)
default:
xargs[i] = fmt.Sprintf("%v", a)
}
}
s = fmt.Sprintf("%s | %s", s, xargs)
}
if Color {
s = color.YellowString(s)
}
logger.Println(s)
}
}
// DialectSupported checks support for the given database dialect
func DialectSupported(d string) bool {
for _, ad := range AvailableDialects {
if ad == d {
return true
}
}
return false
}