Example #1
0
func main() {
	swaggerSpec, err := spec.New(swaggerJSON, "")
	if err != nil {
		log.Fatalln(err)
	}

	port := os.Getenv("PORT")
	if port == "" {
		port = "0"
	}

	host := os.Getenv("HOST")
	if host == "" {
		host = "localhost"
	}

	api := operations.NewEventListAPI(swaggerSpec)
	configureAPI(api)

	listener, err := net.Listen("tcp", host+":"+port)
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf("serving event list at http://%s\n", listener.Addr())

	if err := http.Serve(listener, api.Serve()); err != nil {
		log.Fatalln(err)
	}
}
Example #2
0
func main() {
	swaggerSpec, err := spec.New(SwaggerJSON, "")
	if err != nil {
		log.Fatalln(err)
	}

	parser := flags.NewParser(&opts, flags.Default)
	parser.ShortDescription = swaggerSpec.Spec().Info.Title
	parser.LongDescription = swaggerSpec.Spec().Info.Description

	if _, err := parser.Parse(); err != nil {
		os.Exit(1)
	}

	api := operations.NewEventListAPI(swaggerSpec)
	handler := configureAPI(api)

	httpServer := &graceful.Server{Server: new(http.Server)}
	httpServer.Handler = handler

	listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", opts.Host, opts.Port))
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Printf("serving event list at http://%s\n", listener.Addr())
	if err := httpServer.Serve(tcpKeepAliveListener{listener.(*net.TCPListener)}); err != nil {
		log.Fatalln(err)
	}

}