mozhi/utils/main.go

26 lines
561 B
Go
Raw Normal View History

2023-08-15 21:41:02 +05:30
package utils
2023-10-11 15:57:28 +05:30
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)
}
}
2023-08-15 21:41:02 +05:30
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 ""
}