Skip to content

Commit

Permalink
feat!: return value from resourcename.ParsePattern
Browse files Browse the repository at this point in the history
To match the API of resourcetype.ParseName - both these structs are
small, and can be passed around on the stack.
  • Loading branch information
odsod committed Dec 27, 2020
1 parent c736504 commit 36aaa23
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions resourcename/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func (p *Pattern) NonVariableLen() int {
// Template = Segment { "/" Segment } ;
// Segment = LITERAL | Variable ;
// Variable = "{" LITERAL "}" ;
func ParsePattern(s string) (*Pattern, error) {
func ParsePattern(s string) (Pattern, error) {
if len(s) == 0 {
return nil, fmt.Errorf("parse pattern: empty")
return Pattern{}, fmt.Errorf("parse pattern: empty")
}
result := Pattern{StringVal: s}
for _, value := range strings.Split(s, "/") {
if len(value) == 0 {
return nil, fmt.Errorf("parse pattern: invalid format")
return Pattern{}, fmt.Errorf("parse pattern: invalid format")
}
segment := Segment{
Variable: value[0] == '{' && value[len(value)-1] == '}',
Expand All @@ -91,5 +91,5 @@ func ParsePattern(s string) (*Pattern, error) {
}
result.Segments = append(result.Segments, segment)
}
return &result, nil
return result, nil
}

0 comments on commit 36aaa23

Please sign in to comment.