Beispiel #1
0
func initConfig() {
	util.LoadConfig()
	authn.InitValidator()

	sc := make(chan os.Signal, 1)

	signal.Notify(sc, syscall.SIGHUP)

	go func() {
		for {
			<-sc
			util.LoadConfig()
		}
	}()
}
Beispiel #2
0
func main() {
	defer log.Flush()
	log.Infof("app start")

	// load config
	config = util.LoadConfig()
	log.Debug(config)
	// session init
	session.LoadSession(config["session.name"], config["session.maxAge"])
	// route init
	route.LoadRoute(config["static.base"])
	router := route.Register()
	// view init
	var isCache bool
	if config["view.isCache"] == "true" {
		isCache = true
	} else {
		isCache = false
	}
	view.LoadView(config["view.postFix"], config["view.layoutFolder"], config["view.defaultLayout"],
		config["view.folder"], isCache)
	view.LoadPlugins(
		plugin.NoEscape(),
	)

	go func() {
		log.Info("listen and serve 8089")
		log.Info(http.ListenAndServe(":8089", route.MiddleHandle(router)))
	}()

	sigChan := make(chan int)
	go func() {
		c := make(chan os.Signal, 1)
		signal.Notify(c, os.Interrupt, os.Kill)
		for {
			select {
			case <-c:
				log.Info("App quit by signal")
				sigChan <- 1
			case <-util.ExitChan:
				log.Info("App quit manually")
				sigChan <- 1
			}
		}
	}()
	<-sigChan
}
Beispiel #3
0
// Generate a token based on the key file and username
func main() {
	var password string
	var username string
	const required = "REQUIRED"

	be := logging.NewLogBackend(os.Stderr, "", 0)

	logging.SetBackend(be)
	logging.SetLevel(logging.CRITICAL, "")

	flag.StringVar(&username, "user", required, "Username to create the token for")
	flag.StringVar(&password, "pwd", required, "Password to use")

	flag.Parse()

	if username == required || password == required {
		flag.PrintDefaults()
		return
	}

	util.LoadConfig()
	fmt.Printf("%s=%s\n", username, pwd.HashPassword(password))
}