示例#1
0
func main() {
	flag.Parse()
	listen := fmt.Sprintf("%s:%d", *host, *port)

	lo, ll, err := logger.StringToFlag(*logOutput, *logLevel)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	logger.New(lo, ll)

	if *db == "" {
		logger.Error.Println("A db connection string (flag --db='') is required.\n" + dbConnectionHelp)
		os.Exit(1)
	}

	if err = models.New(*db); err != nil {
		logger.Error.Println(err)
		os.Exit(1)
	}

	if *migrate {
		logger.Info.Println("Migrating Database.")
		models.Migrate()
		os.Exit(0)
	}

	r := mux.NewRouter()
	r.StrictSlash(true)
	auth.New(r)

	http.Handle("/", r)
	logger.Info.Printf("Chatterbox listening on %s.\n", listen)
	http.ListenAndServe(listen, nil)
}
示例#2
0
// NewMockLogger creates a new mock logger
func NewMockLogger() {
	logger.New(logger.Mconsole, logger.Ldebug)
}