NewGroup returns a version Group based on the given "version" constraint. Group completes the Party interface. The returned Group wraps a cloned Party of the given "r" Party therefore, any changes to its parent won't affect this one (e.g. register global middlewares afterwards). A version is extrac
(r API, version string)
| 84 | // |
| 85 | // but not `4.2.1`, `2.1.1` |
| 86 | func NewGroup(r API, version string) *Group { |
| 87 | version = strings.ReplaceAll(version, ",", " ") |
| 88 | version = strings.TrimSpace(version) |
| 89 | |
| 90 | verRange, err := semver.ParseRange(version) |
| 91 | if err != nil { |
| 92 | r.Logger().Errorf("versioning: %s: %s", r.GetRelPath(), strings.ToLower(err.Error())) |
| 93 | return &Group{API: r} |
| 94 | } |
| 95 | |
| 96 | // Clone this one. |
| 97 | r = r.Party("/") |
| 98 | |
| 99 | // Note that this feature alters the RouteRegisterRule to RouteOverlap |
| 100 | // the RouteOverlap rule does not contain any performance downside |
| 101 | // but it's good to know that if you registered other mode, this wanna change it. |
| 102 | r.SetRegisterRule(router.RouteOverlap) |
| 103 | |
| 104 | handler := makeHandler(verRange) |
| 105 | // This is required in order to not populate this middleware to the next group. |
| 106 | r.UseOnce(handler) |
| 107 | // This is required for versioned custom error handlers, |
| 108 | // of course if the parent registered one then this will do nothing. |
| 109 | r.UseError(handler) |
| 110 | |
| 111 | return &Group{ |
| 112 | API: r, |
| 113 | validate: verRange, |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // Deprecated marks this group and all its versioned routes |
| 118 | // as deprecated versions of that endpoint. |
searching dependent graphs…