func NewServer(addr string, logger *zap.SugaredLogger, a API, opts ...Option) http.Server {

	// Create our server
	s := server{
		router: httptreemux.New(),
		logger: logger,
		mw:     make([]Middleware, 0),
	}

	for _, opt := range opts {
		opt(&s)
	}

	// Gather endpoints to register with metrics middleware.
	// Some endpoints may not wish to be instrumented.
	metricEndpoints := make([]Endpoint, 0)
	for _, e := range a.Endpoints() {
		if !e.SuppressMetrics {
			metricEndpoints = append(metricEndpoints, e)
		}
	}

	// Create metrics middleware.
	metricsmw := MetricsMW(prometheus.DefaultRegisterer, metricEndpoints)

	// Create logging middleware.
	logmw := LogMW(logger)

	// Add all endpoints to the server's router.
	for _, e := range a.Endpoints() {

		methods := []string{e.Method}

		// Gather list of middleware to wrap this endpoint in.
		mws := make([]Middleware, 0)
		if !e.SuppressMetrics {
			// Add metrics middleware if metrics should not be suppressed.
			mws = append(mws, metricsmw)
		}
		if !e.SuppressLogs {
			// Add logging middleware if logs should not be suppressed.
			mws = append(mws, logmw)
		}
		if e.CorsMiddleware != nil {
			// Add cors middleware.
			mws = append(mws, Middleware(*e.CorsMiddleware))
			// Add OPTIONS method to be registered.
			methods = append(methods, "OPTIONS")
		}

		// Add all of the endpoint specific middleware.
		mws = append(mws, e.Middlewares...)

		for _, method := range methods {
			// Register endpoint with the server.
			s.handle(method, e.Path, e.Handler, mws...)
		}
	}

	// Convert our server into a http.Server
	return http.Server{
		Addr:    addr,
		Handler: &s,
	}
}
// NewServer returns a HTTP server for accessing the the given API.
NewServer returns a HTTP server for accessing the the given API.
// NewServer returns a HTTP server for accessing the the given API .
func NewServer(addr string, logger *zap.SugaredLogger, a API, opts ...Option) http.Server {
	s := server{
		router: httptreemux.New(),
		logger: logger,
		mw:     make([]Middleware, 0),
	}
	for _, opt := range opts {
		opt(&s)
	}
	metricEndpoints := make([]Endpoint, 0)
	for _, e := range a.Endpoints() {
		if !e.SuppressMetrics {
			metricEndpoints = append(metricEndpoints, e)
		}
	}
	metricsmw := MetricsMW(prometheus.DefaultRegisterer, metricEndpoints)
	logmw := LogMW(logger)
	for _, e := range a.Endpoints() {
		methods := []string{e.Method}
		mws := make([]Middleware, 0)
		if !e.SuppressMetrics {
			mws = append(mws, metricsmw)
		}
		if !e.SuppressLogs {
			mws = append(mws, logmw)
		}
		if e.CorsMiddleware != nil {
			mws = append(mws, Middleware(*e.CorsMiddleware))
			methods = append(methods, "OPTIONS")
		}
		mws = append(mws, e.Middlewares...)
		for _, method := range methods {
			s.handle(method, e.Path, e.Handler, mws...)
		}
	}
	return http.Server{
		Addr:    addr,
		Handler: &s,
	}
}
func NewServer ( addr string , logger * zap . SugaredLogger , a API , opts ... Option ) http . Server { s := server { router : httptreemux . New ( ) , logger : logger , mw : make ( [ ] Middleware , 0 ) , } for _ , opt := range opts { opt ( & s ) } metricEndpoints := make ( [ ] Endpoint , 0 ) for _ , e := range a . Endpoints ( ) { if ! e . SuppressMetrics { metricEndpoints = append ( metricEndpoints , e ) } } metricsmw := MetricsMW ( prometheus . DefaultRegisterer , metricEndpoints ) logmw := LogMW ( logger ) for _ , e := range a . Endpoints ( ) { methods := [ ] string { e . Method } mws := make ( [ ] Middleware , 0 ) if ! e . SuppressMetrics { mws = append ( mws , metricsmw ) } if ! e . SuppressLogs { mws = append ( mws , logmw ) } if e . CorsMiddleware != nil { mws = append ( mws , Middleware ( * e . CorsMiddleware ) ) methods = append ( methods , " " ) } mws = append ( mws , e . Middlewares ... ) for _ , method := range methods { s . handle ( method , e . Path , e . Handler , mws ... ) } } return http . Server { Addr : addr , Handler : & s , } }
NewServer returns a HTTP server for accessing the the given API.
NewServer returns a HTTP server for accessing the the given API .
// Create our server // Gather endpoints to register with metrics middleware. // Some endpoints may not wish to be instrumented. // Create metrics middleware. // Create logging middleware. // Add all endpoints to the server's router. // Gather list of middleware to wrap this endpoint in. // Add metrics middleware if metrics should not be suppressed. // Add logging middleware if logs should not be suppressed. // Add cors middleware. // Add OPTIONS method to be registered. // Add all of the endpoint specific middleware. // Register endpoint with the server. // Convert our server into a http.Server