Пример #1
0
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)
	}
}
Пример #2
0
func main() {
	flag.Parse()

	semail := strings.TrimSpace(*email)
	semail = strings.ToLower(semail)
	spwd := strings.TrimSpace(*pwd)

	var err error
	saction := *action
	switch saction {
	case "adduser":
		initMongo()
		auth.SetUserStorageToMongo()
		err = addUser(semail, spwd)
		if err == nil {
			fmt.Println("success add user:"******"setadmin":
		initMongo()
		err = setAdmin(semail, *adminLevel)
		if err == nil {
			fmt.Printf("success set %s to admin\n", semail)
		}
	default:
		if saction == "" {
			err = fmt.Errorf("please enter action")
		} else {
			err = fmt.Errorf("wrong action [%s]", saction)
		}
	}
	if err != nil {
		log.Fatalln("add user error: ", err.Error())
	}
}