1
1
package main
2
2
3
3
import (
4
- "flag"
5
4
"fmt"
6
5
"os"
7
- "strings"
8
6
9
7
"github.com/docker/go-plugins-helpers/volume"
8
+ "github.com/libgolang/config"
10
9
"github.com/libgolang/docker-volume-linode/linode"
11
10
"github.com/libgolang/log"
12
11
)
13
12
14
13
var (
15
- token string
16
- logLevelParamPtr = param ("log.leve" , "DEBUG" , "Log Level" )
17
- logTraceParamPtr = flag .Bool ("log.trace" , false , "Set Tracing to true" )
18
-
19
- linodeTokenParamPtr = param ("linode.token" , "" , "Required Personal Access Token generated in Linode Console." )
20
- hostParamPtr = param ("host" , hostname (), "Sets the cluster region" )
21
- regionParamPtr = param ("region" , "us-west" , "Sets the cluster region" )
14
+ token string
15
+ logLevelParamPtr = config .String ("log.leve" , "INFO" , "Log Level. Defaults to WARN" )
16
+ logTraceParamPtr = config .Bool ("log.trace" , false , "Set Tracing to true" )
17
+ linodeTokenParamPtr = config .String ("linode.token" , "" , "Required Personal Access Token generated in Linode Console." )
18
+ hostParamPtr = config .String ("linode.host" , hostname (), "Sets the cluster region" )
19
+ regionParamPtr = config .String ("linode.region" , "us-west" , "Sets the cluster region" )
22
20
)
23
21
24
22
func main () {
25
- flag .Parse ()
23
+ config .AppName = "docker-volume-linode"
24
+ config .Parse ()
26
25
27
26
//
28
- //
29
- log .SetTrace (true )
30
- w := & log.WriterStdout {}
31
- w .SetLevel (log .DEBUG )
32
- log .SetWriters ([]log.Writer {w })
33
-
34
- //
35
- // Get token from `-linode.token` param or from LINODE_TOKEN environment variable
36
- //
37
- if * linodeTokenParamPtr != "" {
38
- token = * linodeTokenParamPtr
39
- } else {
40
- token = os .Getenv ("LINODE_TOKEN" )
41
- }
42
- os .Setenv ("LOG_CONFIG" , "" )
43
- log .Debug ("Using linode token: %s" , token )
27
+ log .GetDefaultWriter ().SetLevel (log .StrToLevel (* logLevelParamPtr ))
28
+ log .SetTrace (* logTraceParamPtr )
44
29
45
30
// Linode API instance
46
31
linodeAPI := linode .NewAPI (token , * regionParamPtr , * hostParamPtr )
@@ -53,18 +38,6 @@ func main() {
53
38
fmt .Println (handler .ServeUnix ("linode-driver" , 0 ))
54
39
}
55
40
56
- func param (key , def , help string ) * string {
57
- envKey := strings .Replace (strings .ToUpper (key ), "." , "_" , - 1 )
58
- return flag .String (key , getEnv (envKey , def ), help )
59
- }
60
-
61
- func getEnv (key , def string ) string {
62
- if val , ok := os .LookupEnv (key ); ok {
63
- return val
64
- }
65
- return def
66
- }
67
-
68
41
func hostname () string {
69
42
h , _ := os .Hostname ()
70
43
return h
0 commit comments