fyp/logic/utils/utils.go

25 lines
483 B
Go
Raw Normal View History

package utils
import (
"errors"
2024-04-14 14:51:16 +01:00
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
)
2024-03-09 10:52:08 +00:00
func GetIdFromUrl(c *Context, target string) (string, error) {
if !c.R.URL.Query().Has(target) {
2024-02-08 18:20:58 +00:00
return "", errors.New("Query does not have " + target)
}
2024-03-09 10:52:08 +00:00
id := c.R.URL.Query().Get("id")
if len(id) == 0 {
2024-02-08 18:20:58 +00:00
return "", errors.New("Query is empty for " + target)
}
if !IsValidUUID(id) {
2024-02-08 18:20:58 +00:00
return "", errors.New("Value of query is not a valid uuid for " + target)
}
2024-02-08 18:20:58 +00:00
return id, nil
}