22 lines
701 B
Go
22 lines
701 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"cloud.o-forge.io/core/oc-lib/tools"
|
|
)
|
|
|
|
func ExtractMethod(relation string, internal bool) (tools.METHOD, error) {
|
|
meths := []tools.METHOD{tools.GET, tools.PUT, tools.POST, tools.DELETE}
|
|
if internal {
|
|
meths = append(meths, []tools.METHOD{tools.STRICT_INTERNAL_GET, tools.STRICT_INTERNAL_POST, tools.STRICT_INTERNAL_POST, tools.STRICT_INTERNAL_DELETE}...)
|
|
}
|
|
for _, method := range meths {
|
|
if (!internal && strings.Contains(strings.ToUpper(relation), strings.ToUpper(method.String()))) || (internal && strings.ToUpper(relation) == strings.ToUpper(method.String())) {
|
|
return method, nil
|
|
}
|
|
}
|
|
return tools.GET, errors.New("method not found")
|
|
}
|