parser
API
parser
packageAPI reference for the parser
package.
S
struct
Policy
Policy represents the security rules extracted from a struct tag.
pkg/parser/parser.go:8-12
type Policy struct
Fields
| Name | Type | Description |
|---|---|---|
| Roles | []string | |
| Permissions | map[string][]string | |
| UseValueAsRole | bool |
F
function
Parse
Parse extracts policy information from a ‘guard’ struct tag.
Parameters
tag
string
Returns
pkg/parser/parser.go:17-38
func Parse(tag string) *Policy
{
p := &Policy{
Permissions: make(map[string][]string),
}
parsed := tagParser.Parse(tag)
for key, values := range parsed {
if key == "role" {
if len(values) == 1 && values[0] == "*" {
p.UseValueAsRole = true
} else {
p.Roles = append(p.Roles, values...)
}
continue
}
p.Permissions[key] = values
}
return p
}