增加启动静态资源服务器方法 #10

Merged
zhangdeman merged 1 commits from feature/gin into master 2021-12-24 14:36:22 +08:00
2 changed files with 43 additions and 0 deletions

18
gin/static/define.go Normal file
View File

@ -0,0 +1,18 @@
// Package static ...
//
// Description : static
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021/12/24 2:18 PM
package static
// MapRule 定义映射规则
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:18 PM 2021/12/24
type MapRule struct {
URIPrefix string `json:"uri_prefix"` // 路由前缀
StaticDirPath string `json:"static_dir_path"` // 静态资源路由
}

25
gin/static/static.go Normal file
View File

@ -0,0 +1,25 @@
// Package static ...
//
// Description : 启动静态资源服务器
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2021/12/24 2:14 PM
package static
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Register 静态资源服务器
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:17 PM 2021/12/24
func Register(router *gin.Engine, ruleList []*MapRule) {
for _, rule := range ruleList {
router.StaticFS(rule.URIPrefix, http.Dir(rule.StaticDirPath))
}
}