MCPcopy Create free account
hub / github.com/kataras/iris / GetVersion

Function GetVersion

versioning/version.go:145–184  ·  view source on GitHub ↗

GetVersion returns the current request version. By default the `GetVersion` will try to read from: - "Accept" header, i.e Accept: "application/json; version=1.0.0" - "Accept-Version" header, i.e Accept-Version: "1.0.0" However, the end developer can also set a custom version for a handler via a mi

(ctx *context.Context)

Source from the content-addressed store, hash-verified

143//
144// See `SetVersion` too.
145func GetVersion(ctx *context.Context) string {
146 // firstly by context store, if manually set by a middleware.
147 version := ctx.Values().GetString(ctx.Application().ConfigurationReadOnly().GetVersionContextKey())
148 if version != "" {
149 return version
150 }
151
152 // secondly by the "Accept-Version" header.
153 if version = ctx.GetHeader(AcceptVersionHeaderKey); version != "" {
154 return version
155 }
156
157 // thirdly by the "Accept" header which is like"...; version=1.0"
158 acceptValue := ctx.GetHeader(AcceptHeaderKey)
159 if acceptValue != "" {
160 if idx := strings.Index(acceptValue, AcceptHeaderVersionValue); idx != -1 {
161 rem := acceptValue[idx:]
162 startVersion := strings.Index(rem, "=")
163 if startVersion == -1 || len(rem) < startVersion+1 {
164 return ""
165 }
166
167 rem = rem[startVersion+1:]
168
169 end := strings.Index(rem, " ")
170 if end == -1 {
171 end = strings.Index(rem, ";")
172 }
173 if end == -1 {
174 end = len(rem)
175 }
176
177 if version = rem[:end]; version != "" {
178 return version
179 }
180 }
181 }
182
183 return ""
184}
185
186// SetVersion force-sets the API Version.
187// It can be used inside a middleware.

Callers 4

TestGetVersionFunction · 0.92
TestVersionAliasesFunction · 0.92
TestDeprecatedFunction · 0.92
matchVersionRangeFunction · 0.85

Calls 7

ApplicationMethod · 0.80
GetHeaderMethod · 0.80
GetVersionContextKeyMethod · 0.65
ConfigurationReadOnlyMethod · 0.65
IndexMethod · 0.65
GetStringMethod · 0.45
ValuesMethod · 0.45

Tested by 3

TestGetVersionFunction · 0.74
TestVersionAliasesFunction · 0.74
TestDeprecatedFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…