github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/pkg/server/http/cors.go (about)

     1  package http
     2  
     3  import (
     4  	"github.com/lastbackend/toolkit/pkg/server"
     5  	"net/http"
     6  )
     7  
     8  const corsMiddlewareKind server.KindMiddleware = "corsMiddleware"
     9  
    10  type corsMiddleware struct {
    11  	server.DefaultHttpServerMiddleware
    12  	handler http.HandlerFunc
    13  }
    14  
    15  func (corsMiddleware) Kind() server.KindMiddleware {
    16  	return corsMiddlewareKind
    17  }
    18  
    19  func (corsMiddleware) Order() int {
    20  	return 999
    21  }
    22  
    23  func (s *corsMiddleware) Apply(h http.HandlerFunc) http.HandlerFunc {
    24  	return func(w http.ResponseWriter, r *http.Request) {
    25  		s.handler(w, r)
    26  		h.ServeHTTP(w, r)
    27  	}
    28  }