weixin_39732866 2020-11-19 11:28
浏览 0

Go is not serving static files - Switch web framework

From httprouter to echo. - [x] Get list to work - [x] Get creation to work - [x] Get delete to work - [x] Modify endpoint subgenerator - [x] Get http/2 to work - [x] Clean up

  • 写回答

9条回答 默认 最新

  • weixin_39732866 2020-11-19 11:28
    关注

    In echo, it's much more straight forward:

     go
    package main
    
    import (
        "fmt"
        "net/http"
    
        "github.com/labstack/echo"
        "github.com/labstack/echo/engine/fasthttp"
        "github.com/labstack/echo/middleware"
    )
    
    type U struct {
        N string `json:"name"`
    }
    
    func main() {
        port := ":3000"
    
        fmt.Println(port)
    
        e := echo.New()
    
        e.Use(middleware.Static(""))
        e.Use(middleware.Static("client/dev"))
    
        e.Get("/api", func(c echo.Context) error {
            u := U{N: "abcdef"}
    
            return c.JSON(http.StatusOK, u)
        })
    
        e.Run(fasthttp.New(port))
    }
    

    I'll create a branch today to get this fixed.

    评论

报告相同问题?