47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
|
package nf
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func verifyHandlers(path string, handlers ...HandlerFunc) {
|
||
|
if len(handlers) == 0 {
|
||
|
panic(fmt.Sprintf("missing handler in route: %s", path))
|
||
|
}
|
||
|
|
||
|
for _, handler := range handlers {
|
||
|
if handler == nil {
|
||
|
panic(fmt.Sprintf("nil handler found in route: %s", path))
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// parseVendorSpecificContentType check if content type is vendor specific and
|
||
|
// if it is parsable to any known types. If it's not vendor specific then returns
|
||
|
// the original content type.
|
||
|
func parseVendorSpecificContentType(cType string) string {
|
||
|
plusIndex := strings.Index(cType, "+")
|
||
|
|
||
|
if plusIndex == -1 {
|
||
|
return cType
|
||
|
}
|
||
|
|
||
|
var parsableType string
|
||
|
if semiColonIndex := strings.Index(cType, ";"); semiColonIndex == -1 {
|
||
|
parsableType = cType[plusIndex+1:]
|
||
|
} else if plusIndex < semiColonIndex {
|
||
|
parsableType = cType[plusIndex+1 : semiColonIndex]
|
||
|
} else {
|
||
|
return cType[:semiColonIndex]
|
||
|
}
|
||
|
|
||
|
slashIndex := strings.Index(cType, "/")
|
||
|
|
||
|
if slashIndex == -1 {
|
||
|
return cType
|
||
|
}
|
||
|
|
||
|
return cType[0:slashIndex+1] + parsableType
|
||
|
}
|