diff options
| author | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-30 23:43:46 +0300 |
|---|---|---|
| committer | Hamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com> | 2023-05-30 23:43:46 +0300 |
| commit | a2d8c98b0df39216787d2c77af6e499857510e9e (patch) | |
| tree | b0c8674e985b5c1206d40886ad150d24fbd7552b /web/middleware/domainValidator.go | |
| parent | 8442836512d82b705e404bc1749e3000115ba550 (diff) | |
create and move middlewares to seperate folder
Diffstat (limited to 'web/middleware/domainValidator.go')
| -rw-r--r-- | web/middleware/domainValidator.go | 21 |
1 files changed, 21 insertions, 0 deletions
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() + } +} |
