func main() { flag.Parse() f, err := os.Open(*configFile) if err != nil { die("cannot open config file: %s", err) } defer f.Close() conf, err := config.Read(f) if err != nil { die("cannot read config file: %s", err) } if err := config.Check(conf); err != nil { die("invalid config file: %s", err) } DB := db.Driver(conf.DB.Driver) if DB == nil { die("unknown database driver %s", conf.DB.Driver) } if err := DB.Open(conf.DB.DSN); err != nil { die("cannot open database: %s", err) } s, err := server.New(conf, DB) if err != nil { die("%s", err) } log.Fatalln(http.ListenAndServe(conf.Server.ListenAddress, s)) }
func readConfig(path string) (*config.Config, error) { f, err := os.Open(path) if err != nil { return nil, err } defer f.Close() return config.Read(f) }