File tree Expand file tree Collapse file tree 5 files changed +29
-17
lines changed Expand file tree Collapse file tree 5 files changed +29
-17
lines changed Original file line number Diff line number Diff line change 1+ package echo
2+
3+ import (
4+ "github.com/3JoB/httpfileserver"
5+ "github.com/labstack/echo/v4"
6+ )
7+
8+ func EchoHandle (fs * httpfileserver.FileServer ) echo.HandlerFunc {
9+ return func (c echo.Context ) error {
10+ fs .ServeHTTP (c .Response ().Writer , c .Request ())
11+ return nil
12+ }
13+ }
Original file line number Diff line number Diff line change 55 "github.com/labstack/echo/v4/middleware"
66
77 "github.com/3JoB/httpfileserver"
8+ he "github.com/3JoB/httpfileserver/echo"
89)
910
1011func main () {
@@ -13,6 +14,6 @@ func main() {
1314 e .Use (middleware .Logger ())
1415 e .Use (middleware .Recover ())
1516
16- e .GET ("*" , httpfileserver .New ("/assets/" , "." ). EchoHandle ( ))
17+ e .GET ("*" , he . EchoHandle ( httpfileserver .New ("/assets/" , "." )))
1718 e .Logger .Fatal (e .Start (":1113" ))
1819}
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ import (
44 "github.com/gin-gonic/gin"
55
66 "github.com/3JoB/httpfileserver"
7+ hg "github.com/3JoB/httpfileserver/gin"
78)
89
910func main () {
1011 r := gin .New ()
11- r .GET ("*" , httpfileserver .New ("/assets/" , "." ). GinHandle ( ))
12+ r .GET ("*" , hg . GinHandle ( httpfileserver .New ("/assets/" , "." )))
1213 r .Run (":1122" )
1314}
Original file line number Diff line number Diff line change 1+ package gin
2+
3+ import (
4+ "github.com/3JoB/httpfileserver"
5+ "github.com/gin-gonic/gin"
6+ )
7+
8+ func GinHandle (fs * httpfileserver.FileServer ) gin.HandlerFunc {
9+ return func (c * gin.Context ) {
10+ fs .ServeHTTP (c .Writer , c .Request )
11+ }
12+ }
Original file line number Diff line number Diff line change @@ -10,11 +10,9 @@ import (
1010 "time"
1111
1212 "github.com/andybalholm/brotli"
13- "github.com/gin-gonic/gin"
1413 "github.com/klauspost/compress/flate"
1514 "github.com/klauspost/compress/gzip"
1615 "github.com/klauspost/compress/zstd"
17- "github.com/labstack/echo/v4"
1816)
1917
2018type FileServer struct {
@@ -141,19 +139,6 @@ func (fs *FileServer) Handle() http.HandlerFunc {
141139 return fs .ServeHTTP
142140}
143141
144- func (fs * FileServer ) EchoHandle () echo.HandlerFunc {
145- return func (c echo.Context ) error {
146- fs .ServeHTTP (c .Response ().Writer , c .Request ())
147- return nil
148- }
149- }
150-
151- func (fs * FileServer ) GinHandle () gin.HandlerFunc {
152- return func (c * gin.Context ) {
153- fs .ServeHTTP (c .Writer , c .Request )
154- }
155- }
156-
157142// ServeHTTP is the server of the file server
158143func (fs * FileServer ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
159144 r .URL .Path = strings .TrimPrefix (r .URL .Path , fs .route )
You can’t perform that action at this time.
0 commit comments