forked from gramework/gramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
45 lines (38 loc) · 973 Bytes
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gramework
// SetName for the server
func (app *App) SetName(name string) {
app.name = name
}
// ToTLSHandler returns handler that redirects user to HTTPS scheme
func (app *App) ToTLSHandler() func(*Context) {
return func(ctx *Context) {
ctx.ToTLS()
}
}
// HTTP returns HTTP-only router
func (app *App) HTTP() *Router {
return app.defaultRouter.HTTP()
}
// HTTPS returns HTTPS-only router
func (app *App) HTTPS() *Router {
return app.defaultRouter.HTTPS()
}
// MethodNotAllowed sets MethodNotAllowed handler
func (app *App) MethodNotAllowed(c func(ctx *Context)) *App {
app.defaultRouter.router.MethodNotAllowed = c
return app
}
// Redir sends 301 redirect to the given url
//
// it's equivalent to
//
// ctx.Redirect(url, 301)
func (app *App) Redir(url string) func(*Context) {
return func(ctx *Context) {
ctx.Redirect(url, redirectCode)
}
}
// Forbidden send 403 Forbidden error
func (app *App) Forbidden(ctx *Context) {
ctx.Forbidden()
}