@@ -97,6 +97,7 @@ var validHttpStatusCode = map[uint]struct{}{
9797 uint(runtime.StatusNetworkAuthenticationRequired): {},
9898}
9999
100+ // GetValidHttpVerbs returns a list of all valid HTTP verbs
100101func GetValidHttpVerbs() []string {
101102 verbs := make([]string, 0, len(validHttpVerbs))
102103 for verb := range validHttpVerbs {
@@ -105,12 +106,14 @@ func GetValidHttpVerbs() []string {
105106 return verbs
106107}
107108
109+ // GetRouteSupportedHttpVerbs returns a list of all HTTP verbs that are valid in the context of an API Endpoint
108110func GetRouteSupportedHttpVerbs() []string {
109111 verbs := common.MapKeys(routeSupportedHttpVerbs)
110112 slices.Sort(verbs)
111113 return verbs
112114}
113115
116+ // GetValidHttpStatusCodes returns a list of all known/valid HTTP Status Codes
114117func GetValidHttpStatusCodes() []uint {
115118 codes := make([]uint, 0, len(validHttpStatusCode))
116119 for code := range validHttpStatusCode {
@@ -119,28 +122,27 @@ func GetValidHttpStatusCodes() []uint {
119122 return codes
120123}
121124
125+ // IsValidHttpVerb determines whether a given string is a valid HTTP verb
122126func IsValidHttpVerb(verb string) bool {
123127 _, exists := validHttpVerbs[verb]
124128 return exists
125129}
126130
131+ // IsValidRouteHttpVerb determines whether a given string is an HTTP verb
132+ // that is valid in the context of an API endpoint
127133func IsValidRouteHttpVerb(verb string) bool {
128134 _, exists := routeSupportedHttpVerbs[verb]
129135 return exists
130136}
131137
132- func EnsureValidHttpVerb(verb string) HttpVerb {
133- if IsValidHttpVerb(verb) {
134- return HttpVerb(verb)
135- }
136- panic(fmt.Sprintf("'%s' is not a valid HTTP verb", verb))
137- }
138-
138+ // IsValidHttpStatusCode determines whether the given code is a known, valid HTTP Status Code
139139func IsValidHttpStatusCode(code uint) bool {
140140 _, exists := validHttpStatusCode[code]
141141 return exists
142142}
143143
144+ // ConvertToHttpStatus attempts to convert the given code into an HTTP Status Code.
145+ // Returns an error if the given code is invalid.
144146func ConvertToHttpStatus(code string) (runtime.HttpStatusCode, error) {
145147 parsed, err := strconv.ParseUint(code, 10, 32)
146148 if err != nil {
@@ -154,6 +156,9 @@ func ConvertToHttpStatus(code string) (runtime.HttpStatusCode, error) {
154156 return runtime.HttpStatusCode(parsedCode), nil
155157}
156158
159+ // PermissionStringToFileMod converts the given permission string into a FileMode.
160+ //
161+ // Input is expected to be a valid octal permission value like '0777'
157162func PermissionStringToFileMod(permissionString string) (os.FileMode, error) {
158163 permission, err := strconv.ParseUint(permissionString, 8, 32)
159164 // A proper mask needs to account for sticky/setuid/setgid bitflags
0 commit comments