mirror of
https://github.com/kataras/iris.git
synced 2026-01-27 22:05:56 +00:00
initialize support for versioning as requested, per route -- not finished yet
Former-commit-id: ade66610125f06a0b5ce3e90bcafe349f216a616
This commit is contained in:
36
versioning/deprecation.go
Normal file
36
versioning/deprecation.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package versioning
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
)
|
||||
|
||||
type DeprecationOptions struct {
|
||||
WarnMessage string
|
||||
DeprecationDate time.Time
|
||||
DeprecationInfo string
|
||||
}
|
||||
|
||||
var DefaultDeprecationOptions = DeprecationOptions{
|
||||
WarnMessage: "WARNING! You are using a deprecated version of this API.",
|
||||
}
|
||||
|
||||
func Deprecated(handler context.Handler, options DeprecationOptions) context.Handler {
|
||||
if options.WarnMessage == "" {
|
||||
options.WarnMessage = DefaultDeprecationOptions.WarnMessage
|
||||
}
|
||||
|
||||
return func(ctx context.Context) {
|
||||
handler(ctx)
|
||||
ctx.Header("X-API-Warn", options.WarnMessage)
|
||||
|
||||
if !options.DeprecationDate.IsZero() {
|
||||
ctx.Header("X-API-Deprecation-Date", context.FormatTime(ctx, options.DeprecationDate))
|
||||
}
|
||||
|
||||
if options.DeprecationInfo != "" {
|
||||
ctx.Header("X-API-Deprecation-Info", options.DeprecationInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user