mirror of
https://codeberg.org/aryak/mozhi
synced 2024-11-18 11:42:57 +05:30
26 lines
561 B
Go
26 lines
561 B
Go
package utils
|
|
|
|
import (
|
|
"github.com/gofiber/fiber/v2"
|
|
"regexp"
|
|
)
|
|
|
|
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 ""
|
|
}
|