From 754ebbdabb2c379c2ab710e6439dd821b17a128e Mon Sep 17 00:00:00 2001 From: Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> Date: Wed, 31 May 2023 03:20:18 +0430 Subject: [PATCH] create and move middlewares to seperate folder --- web/middleware/domainValidator.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 web/middleware/domainValidator.go diff --git a/web/middleware/domainValidator.go b/web/middleware/domainValidator.go new file mode 100644 index 00000000..3adb0f0f --- /dev/null +++ b/web/middleware/domainValidator.go @@ -0,0 +1,21 @@ +package middleware + +import ( + "net/http" + "strings" + + "github.com/gin-gonic/gin" +) + +func DomainValidatorMiddleware(domain string) gin.HandlerFunc { + return func(c *gin.Context) { + host := strings.Split(c.Request.Host, ":")[0] + + if host != domain { + c.AbortWithStatus(http.StatusForbidden) + return + } + + c.Next() + } +}