// Configure initializes all necessary data for the server, including the // configuration data, services and routes. func (s *Server) Configure() error { var err error log.Println("Configuring server...") s.cfg = config.NewConfig() s.cfg.Print() err = s.cfg.Validate() if err != nil { return err } err = s.configureServices() if err != nil { return err } s.configureCookieStore() log.Println("Setting up routes...") s.createMuxRouter() s.configureRouters() s.bindRoutes() log.Println("Creating static file server...") s.createStaticFilesServer() return nil }
// NewServer returns a new instance of the server. All server configuration // is done at the Configure() function. func NewServer() *Server { var ( err error server = &Server{} ) log.Println("Configuring server...") server.cfg = config.NewConfig() server.cfg.Print() err = server.cfg.Validate() if err != nil { log.Fatalln(err) } log.Println("Creating database connection...") server.db, err = server.createDatabaseConn() if err != nil { log.Fatalln(err) } server.configureCookieStore() log.Println("Setting up routes...") server.configureRouter() log.Println("Creating static file server...") server.createStaticFilesServer() return server }