mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-21 19:32:58 +00:00
Merge pull request #680 from Fenny/master
🧹 Remove deprecated Templates
This commit is contained in:
commit
206d3a5aba
8
app.go
8
app.go
@ -140,10 +140,6 @@ type Settings struct {
|
||||
// Default: false
|
||||
DisableStartupMessage bool `json:"disable_startup_message"`
|
||||
|
||||
// Deprecated: Templates is deprecated please use Views.
|
||||
// Default: nil
|
||||
Templates Templates `json:"-"`
|
||||
|
||||
// Views is the interface that wraps the Render function.
|
||||
// Default: nil
|
||||
Views Views `json:"-"`
|
||||
@ -591,10 +587,6 @@ func (app *App) init() *App {
|
||||
app.mutex.Lock()
|
||||
// Load view engine if provided
|
||||
if app.Settings != nil {
|
||||
// Templates is replaced by Views with layout support
|
||||
if app.Settings.Templates != nil {
|
||||
fmt.Println("`Templates` are deprecated since v1.12.x, please use `Views` instead")
|
||||
}
|
||||
// Only load templates if an view engine is specified
|
||||
if app.Settings.Views != nil {
|
||||
if err := app.Settings.Views.Load(); err != nil {
|
||||
|
46
ctx.go
46
ctx.go
@ -67,11 +67,6 @@ type Cookie struct {
|
||||
SameSite string `json:"same_site"`
|
||||
}
|
||||
|
||||
// Templates is deprecated since v1.11.1, please use Views
|
||||
type Templates interface {
|
||||
Render(io.Writer, string, interface{}) error
|
||||
}
|
||||
|
||||
// Views is the interface that wraps the Render function.
|
||||
type Views interface {
|
||||
Load() error
|
||||
@ -468,38 +463,6 @@ func (ctx *Ctx) Fresh() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// isNoCache checks if the cacheControl header value is a `no-cache`.
|
||||
func isNoCache(cacheControl string) bool {
|
||||
noCacheStrIdx := strings.Index(cacheControl, HeaderCacheControlNoCacheValue)
|
||||
if noCacheStrIdx == -1 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := noCacheStrIdx - 1; i >= 0; i-- {
|
||||
if cacheControl[i] != ' ' {
|
||||
// before `no-cache`, if the first non space character is `,`, then
|
||||
// it's a valid no-cache value.
|
||||
if cacheControl[i] != ',' {
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for i := noCacheStrIdx + len(HeaderCacheControlNoCacheValue); i < len(cacheControl); i++ {
|
||||
if cacheControl[i] != ' ' {
|
||||
// after `no-cache`, if the first non space character is `,`, then
|
||||
// it's a valid no-cache value.
|
||||
if cacheControl[i] != ',' {
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// Get returns the HTTP request header specified by field.
|
||||
// Field names are case-insensitive
|
||||
// Returned value is only valid within the handler. Do not store any references.
|
||||
@ -820,14 +783,7 @@ func (ctx *Ctx) Render(name string, bind interface{}, layouts ...string) (err er
|
||||
buf := bytebufferpool.Get()
|
||||
defer bytebufferpool.Put(buf)
|
||||
|
||||
// Use Templates engine if exist
|
||||
if ctx.app.Settings.Templates != nil {
|
||||
// Render template from Templates
|
||||
fmt.Println("render: `Templates` are deprecated since v1.11.1, please us `Views` instead")
|
||||
if err := ctx.app.Settings.Templates.Render(buf, name, bind); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if ctx.app.Settings.Views != nil {
|
||||
if ctx.app.Settings.Views != nil {
|
||||
// Render template from Views
|
||||
if err := ctx.app.Settings.Views.Render(buf, name, bind, layouts...); err != nil {
|
||||
return err
|
||||
|
35
utils.go
35
utils.go
@ -208,6 +208,40 @@ func parseAddr(raw string) (host, port string) {
|
||||
return raw, ""
|
||||
}
|
||||
|
||||
const noCacheValue = "no-cache"
|
||||
|
||||
// isNoCache checks if the cacheControl header value is a `no-cache`.
|
||||
func isNoCache(cacheControl string) bool {
|
||||
noCacheStrIdx := strings.Index(cacheControl, noCacheValue)
|
||||
if noCacheStrIdx == -1 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := noCacheStrIdx - 1; i >= 0; i-- {
|
||||
if cacheControl[i] != ' ' {
|
||||
// before `no-cache`, if the first non space character is `,`, then
|
||||
// it's a valid no-cache value.
|
||||
if cacheControl[i] != ',' {
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for i := noCacheStrIdx + len(noCacheValue); i < len(cacheControl); i++ {
|
||||
if cacheControl[i] != ' ' {
|
||||
// after `no-cache`, if the first non space character is `,`, then
|
||||
// it's a valid no-cache value.
|
||||
if cacheControl[i] != ',' {
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// https://golang.org/src/net/net.go#L113
|
||||
// Helper methods for application#test
|
||||
type testAddr string
|
||||
@ -460,7 +494,6 @@ const (
|
||||
HeaderWWWAuthenticate = "WWW-Authenticate"
|
||||
HeaderAge = "Age"
|
||||
HeaderCacheControl = "Cache-Control"
|
||||
HeaderCacheControlNoCacheValue = "no-cache"
|
||||
HeaderClearSiteData = "Clear-Site-Data"
|
||||
HeaderExpires = "Expires"
|
||||
HeaderPragma = "Pragma"
|
||||
|
Loading…
x
Reference in New Issue
Block a user