github.com/goravel/framework@v1.13.9/contracts/route/route.go (about) 1 package route 2 3 import ( 4 "net/http" 5 6 contractshttp "github.com/goravel/framework/contracts/http" 7 ) 8 9 type GroupFunc func(router Router) 10 11 //go:generate mockery --name=Route 12 type Route interface { 13 Router 14 // Fallback registers a handler to be executed when no other route was matched. 15 Fallback(handler contractshttp.HandlerFunc) 16 // GlobalMiddleware registers global middleware to be applied to all routes of the router. 17 GlobalMiddleware(middlewares ...contractshttp.Middleware) 18 // Run starts the HTTP server and listens for incoming connections on the specified host. 19 Run(host ...string) error 20 // RunTLS starts the HTTPS server with the provided TLS configuration and listens on the specified host. 21 RunTLS(host ...string) error 22 // RunTLSWithCert starts the HTTPS server with the provided certificate and key files and listens on the specified host and port. 23 RunTLSWithCert(host, certFile, keyFile string) error 24 // ServeHTTP serves HTTP requests. 25 ServeHTTP(writer http.ResponseWriter, request *http.Request) 26 } 27 28 //go:generate mockery --name=Router 29 type Router interface { 30 // Group creates a new router group with the specified handler. 31 Group(handler GroupFunc) 32 // Prefix adds a common prefix to the routes registered with the router. 33 Prefix(addr string) Router 34 // Middleware sets the middleware for the router. 35 Middleware(middlewares ...contractshttp.Middleware) Router 36 37 // Any registers a new route responding to all verbs. 38 Any(relativePath string, handler contractshttp.HandlerFunc) 39 // Get registers a new GET route with the router. 40 Get(relativePath string, handler contractshttp.HandlerFunc) 41 // Post registers a new POST route with the router. 42 Post(relativePath string, handler contractshttp.HandlerFunc) 43 // Delete registers a new DELETE route with the router. 44 Delete(relativePath string, handler contractshttp.HandlerFunc) 45 // Patch registers a new PATCH route with the router. 46 Patch(relativePath string, handler contractshttp.HandlerFunc) 47 // Put registers a new PUT route with the router. 48 Put(relativePath string, handler contractshttp.HandlerFunc) 49 // Options registers a new OPTIONS route with the router. 50 Options(relativePath string, handler contractshttp.HandlerFunc) 51 // Resource registers RESTful routes for a resource controller. 52 Resource(relativePath string, controller contractshttp.ResourceController) 53 54 // Static registers a new route with path prefix to serve static files from the provided root directory. 55 Static(relativePath, root string) 56 // StaticFile registers a new route with a specific path to serve a static file from the filesystem. 57 StaticFile(relativePath, filepath string) 58 // StaticFS registers a new route with a path prefix to serve static files from the provided file system. 59 StaticFS(relativePath string, fs http.FileSystem) 60 }