mozhi/utils/main.go
Arya Kiran 99a4eca07b
All checks were successful
mozhi pipeline / Push Docker image to Codeberg docker registry (push) Successful in 15m6s
mozhi pipeline / Build and publish artifacts (push) Successful in 24m43s
make switchlanguage work with POST
2023-10-11 15:57:28 +05:30

26 lines
561 B
Go

package utils
import (
"regexp"
"github.com/gofiber/fiber/v2"
)
func GetQueryOrFormValue(c *fiber.Ctx, key string) string {
if c.Method() == "POST" {
return c.FormValue(key)
} else {
return c.Query(key)
}
}
func Sanitize(str string, strip string) string {
nonAlphanumericRegex := regexp.MustCompile(`[^a-zA-Z]+`)
nonAlphaRegex := regexp.MustCompile(`[^a-zA-Z0-9]+`)
if strip == "alpha" {
return nonAlphaRegex.ReplaceAllString(str, "")
} else if strip == "alphanumeric" {
return nonAlphanumericRegex.ReplaceAllString(str, "")
}
return ""
}