func main() {
	flag.Parse()

	if showVersion {
		fmt.Fprintln(os.Stderr, os.Args[0], version)
		return
	}

	var config godoauth.Config
	if err := config.Parse(confFile); err != nil {
		fmt.Fprintln(os.Stderr, "error parsing config file: ", err)
		os.Exit(1)
	}

	fmt.Printf("Starting %s version: %s\n", name, version)

	server, err := godoauth.NewServer(&config)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error while creating new server: ", err)
		os.Exit(1)
	}
	server.Start()

	// waiting for a termination signal to clean up
	interruptChan := make(chan os.Signal)
	signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
	<-interruptChan
}
Exemple #2
0
func main() {
	flag.Parse()

	if showVersion {
		fmt.Fprintln(os.Stderr, os.Args[0], version)
		return
	}

	var config godoauth.Config
	if err := config.LoadFromFile(confFile); err != nil {
		fmt.Fprintln(os.Stderr, "error parsing config file: ", err)
		os.Exit(1)
	}

	if err := config.LoadCerts(); err != nil {
		fmt.Fprintln(os.Stderr, "error while loading/veryfing certs: ", err)
	}

	fmt.Printf("Starting %s version: %s\n", name, version)

	timeout, err := time.ParseDuration(config.HTTP.Timeout)
	if err != nil {
		fmt.Fprintln(os.Stderr, "error parsing HTTP read timeout")
		return
	}

	authHandler := &godoauth.TokenAuthHandler{
		Config: &config,
	}

	server := &http.Server{
		Addr:        config.HTTP.Addr,
		Handler:     godoauth.NewHandler(authHandler),
		ReadTimeout: timeout,
	}

	if config.HTTP.TLS.Certificate != "" && config.HTTP.TLS.Key != "" {
		server.ListenAndServeTLS(config.HTTP.TLS.Certificate, config.HTTP.TLS.Key)
		return
	}
	server.ListenAndServe()
}