LEFT | RIGHT |
(no file at all) | |
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 "io/ioutil" | 5 "io/ioutil" |
6 "launchpad.net/goyaml" | 6 "launchpad.net/goyaml" |
7 "launchpad.net/juju/go/log" | 7 "launchpad.net/juju/go/log" |
8 "launchpad.net/juju/go/store" | 8 "launchpad.net/juju/go/store" |
9 stdlog "log" | 9 stdlog "log" |
10 "net/http" | 10 "net/http" |
11 "os" | 11 "os" |
12 "path/filepath" | 12 "path/filepath" |
13 ) | 13 ) |
14 | 14 |
15 func main() { | 15 func main() { |
16 log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags) | 16 log.Target = stdlog.New(os.Stdout, "", stdlog.LstdFlags) |
17 err := serve() | 17 err := serve() |
18 if err != nil { | 18 if err != nil { |
19 fmt.Fprintf(os.Stderr, "%v\n", err) | 19 fmt.Fprintf(os.Stderr, "%v\n", err) |
20 os.Exit(1) | 20 os.Exit(1) |
21 } | 21 } |
22 } | 22 } |
23 | 23 |
24 type config struct { | 24 type config struct { |
25 MongoURL string `yaml:"mongo-url"` | 25 MongoURL string `yaml:"mongo-url"` |
26 » APIAddr string `yaml:"api-addr"` | 26 » APIAddr string `yaml:"api-addr"` |
27 } | 27 } |
28 | 28 |
29 func readConfig(path string, conf interface{}) error { | 29 func readConfig(path string, conf interface{}) error { |
30 f, err := os.Open(path) | 30 f, err := os.Open(path) |
31 if err != nil { | 31 if err != nil { |
32 return fmt.Errorf("opening config file: %v", err) | 32 return fmt.Errorf("opening config file: %v", err) |
33 } | 33 } |
34 data, err := ioutil.ReadAll(f) | 34 data, err := ioutil.ReadAll(f) |
35 f.Close() | 35 f.Close() |
36 if err != nil { | 36 if err != nil { |
(...skipping 28 matching lines...) Expand all Loading... |
65 if err != nil { | 65 if err != nil { |
66 return err | 66 return err |
67 } | 67 } |
68 defer s.Close() | 68 defer s.Close() |
69 server, err := store.NewServer(s) | 69 server, err := store.NewServer(s) |
70 if err != nil { | 70 if err != nil { |
71 return err | 71 return err |
72 } | 72 } |
73 return http.ListenAndServe(conf.APIAddr, server) | 73 return http.ListenAndServe(conf.APIAddr, server) |
74 } | 74 } |
LEFT | RIGHT |