func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) flag.Parse() err := conf.LoadAproxyConfig(*confFile) if err != nil { log.Fatalln(err) } config := conf.Config() if !checkWebDir(config.WebDir) { os.Exit(1) return } mgoConf := config.Db.Mongo err = db.InitMongoDB(mgoConf.Servers, mgoConf.Db) if err != nil { log.Fatalln("Can not set to MongoDB backend config storage.", mgoConf.Servers) } // Set backend-config storage to MongoDB bkconf.SetBackendConfStorageToMongo() // Set user storage to MongoDB auth.SetUserStorageToMongo() // session ssConf := config.Session session.InitSessionServer(ssConf.Domain, ssConf.Cookie, ssConf.Expiration) err = session.SetSessionStoragerToRedis(ssConf.Redis.Addr, ssConf.Redis.Password, ssConf.Redis.Db) if err != nil { log.Fatalln(err) } // login login.InitLoginServer(config.LoginHost, config.AproxyUrlPrefix) // setting manager setting.InitSettingServer(config.WebDir, config.AproxyUrlPrefix) lhost := config.Listen mux := http.NewServeMux() // setting setPre := setting.AproxyUrlPrefix apiApp := setting.NewApiApp() mux.HandleFunc(apiApp.UrlPrefix, apiApp.ServeHTTP) mux.HandleFunc(setPre, setting.StaticServer) // proxy mux.HandleFunc("/", proxy.Proxy) s := &http.Server{ Addr: lhost, Handler: mux, } log.Println("Starting aproxy on " + lhost) err = s.ListenAndServe() if err != nil { log.Fatal(err) } }
func initMongo() { if inited { return } err := conf.LoadAproxyConfig(*confFile) if err != nil { log.Fatalln(err) } config := conf.Config() mgoConf := config.Db.Mongo err = db.InitMongoDB(mgoConf.Servers, mgoConf.Db) if err != nil { log.Fatalln("Can not set to MongoDB backend config storage.", mgoConf.Servers) } inited = true }