mozhi/utils/main.go
Arya Kiran 9ab37afc1a
All checks were successful
mozhi pipeline / Push Docker image to Codeberg docker registry (push) Successful in 16m22s
mozhi pipeline / Build and publish artifacts (push) Successful in 29m21s
allow instance owner to configure default source/target lang (closes #14)
2023-10-20 15:49:51 +05:30

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 ""
}