summaryrefslogtreecommitdiff
path: root/hh.go
blob: 84df871a45d892eb849dccf88dbf5684f2d3f48c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hh

import (
	"net/http"
	"strconv"

	"github.com/google/uuid"
)

func ExtractFromForm(r *http.Request, name string) (string, bool) {
	value := r.Form[name]
	if len(value) == 0 {
		return "", true
	}
	return value[0], false
}

func ExtractFromPath(r *http.Request, name string) (string, bool) {
	value := r.PathValue(name)
	if value == "" {
		return "", true
	}
	return value, false
}

func ExtractFromCookie(r *http.Request, name string) (string, bool) {
	value, err := r.Cookie(name)
	if err != nil {
		return "", true
	}
	return value.Value, false
}

func ConvertToInt(value string) (int, error) {
	return strconv.Atoi(value)
}

func ConvertToString(value string) (string, error) {
	return value, nil
}

func ConvertToUuidUUID(value string) (uuid.UUID, error) {
	return uuid.Parse(value)
}