File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 4343 RelativePath () string
4444 FullPath () string
4545 Method () string
46+ ServeStaticFiles (pattern , path string )
4647 }
4748
4849 // Router is the route group struct
@@ -333,3 +334,20 @@ func (r *Router) FullPath() string {
333334func (r * Router ) Method () string {
334335 return r .method
335336}
337+
338+ // ServeStaticFiles serves the static files
339+ func (r * Router ) ServeStaticFiles (
340+ pattern ,
341+ path string ,
342+ ) {
343+ // Check if the pattern contains a trailing slash and add it
344+ if len (pattern ) == 0 || pattern [len (pattern )- 1 ] != '/' {
345+ pattern = pattern + "/"
346+ }
347+
348+ // Serve the static files
349+ r .mux .HandleFunc (
350+ pattern ,
351+ http .StripPrefix (pattern , http .FileServer (http .Dir (path ))).ServeHTTP ,
352+ )
353+ }
You can’t perform that action at this time.
0 commit comments