“ 作为后端服务,我们免不了要提供一些页面供前端使用。今天我们就来看下gin框架怎么实现网页的输出”
package main
import (
"demo/src/main/routers"
"github.com/gin-gonic/gin"
"io"
"net/http"
"os"
)
func main() {
runWebService()
}
func initWebConfig() {
gin.DisableConsoleColor()
f, _ := os.Create("go.log")
gin.DefaultWriter = io.MultiWriter(f, os.Stdout)
}
func runWebService() {
initWebConfig()
r := gin.New()
r.Use(gin.Logger())
routers.LoadReport(r)
// 重点在这块哦,我们通过下面这行代码,将static目录设置为静态目录
// 同时需要用/static才能访问此目录
r.StaticFS("/static", http.Dir("src/static"))
r.Run(":81")
}
thymeleaf那样的模板渲染,下次我再分享给大家。
--End--