From e152823b21624c0afc5e6e273a675c2f37260a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Fri, 24 Dec 2021 14:31:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=AF=E5=8A=A8=E9=9D=99?= =?UTF-8?q?=E6=80=81=E8=B5=84=E6=BA=90=E6=9C=8D=E5=8A=A1=E5=99=A8=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gin/static/define.go | 18 ++++++++++++++++++ gin/static/static.go | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 gin/static/define.go create mode 100644 gin/static/static.go diff --git a/gin/static/define.go b/gin/static/define.go new file mode 100644 index 0000000..b33448b --- /dev/null +++ b/gin/static/define.go @@ -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"` // 静态资源路由 +} diff --git a/gin/static/static.go b/gin/static/static.go new file mode 100644 index 0000000..36f9ca5 --- /dev/null +++ b/gin/static/static.go @@ -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)) + } +}