/
consts.go
102 lines (89 loc) · 1.85 KB
/
consts.go
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (c) 2022-2024. Author: Ruslan Bikchentaev. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
* Перший приватний програміст.
*/
package apis
import (
"regexp"
"github.com/valyala/fasthttp"
)
// content types
const (
ContentTypeJSON = "application/json"
ContentTypeMultiPart = "multipart/form-data"
)
type tMethod uint8
func (t tMethod) String() string {
return methodNames[t]
}
// const of tMethod type values
const (
GET tMethod = iota
POST
HEAD
PUT
PATCH
DELETE
CONNECT
OPTIONS
TRACE
UNKNOWN
)
var methodNames = []string{
"GET",
"POST",
"HEAD",
"PUT",
"PATCH",
"DELETE",
"CONNECT",
"OPTIONS",
"TRACE",
"UNKNOWN",
}
func methodFromName(nameMethod string) tMethod {
switch nameMethod {
case fasthttp.MethodGet:
return GET
case fasthttp.MethodPost:
return POST
case fasthttp.MethodHead:
return HEAD
case fasthttp.MethodPut:
return PUT
case fasthttp.MethodPatch:
return PATCH
case fasthttp.MethodDelete:
return DELETE
case fasthttp.MethodConnect:
return CONNECT
case fasthttp.MethodOptions:
return OPTIONS
case fasthttp.MethodTrace:
return TRACE
default:
return UNKNOWN
}
}
// const of values ctx parameters names
const (
JSONParams = "JSONparams"
MultiPartParams = "MultiPartParams"
ChildRoutePath = "lastSegment"
ApiVersion = "ACC_VERSION"
IsWrapHandler = "HAS_HANDLER"
ServerName = "name of server httpgo"
ServerVersion = "version of server httpgo"
Database = "DB"
AppStore = "store"
)
const testRouteSuffix = "_test"
const PARAM_REQUIRED = "is required parameter"
// vars fr regexp replacer for Docs
var (
regAbbr = regexp.MustCompile(`<abbr[^<]*>([^<]+)</abbr>`)
regTitle = regexp.MustCompile(`(?m)^#\s+([^\n]+)$`)
regTags = regexp.MustCompile(`\*([^*]+)\**`)
)