123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package beego
- import (
- "encoding/json"
- "mime"
- "net/http"
- "path/filepath"
- "github.com/astaxie/beego/context"
- "github.com/astaxie/beego/logs"
- "github.com/astaxie/beego/session"
- )
- //
- func registerMime() error {
- for k, v := range mimemaps {
- mime.AddExtensionType(k, v)
- }
- return nil
- }
- // register default error http handlers, 404,401,403,500 and 503.
- func registerDefaultErrorHandler() error {
- m := map[string]func(http.ResponseWriter, *http.Request){
- "401": unauthorized,
- "402": paymentRequired,
- "403": forbidden,
- "404": notFound,
- "405": methodNotAllowed,
- "500": internalServerError,
- "501": notImplemented,
- "502": badGateway,
- "503": serviceUnavailable,
- "504": gatewayTimeout,
- }
- for e, h := range m {
- if _, ok := ErrorMaps[e]; !ok {
- ErrorHandler(e, h)
- }
- }
- return nil
- }
- func registerSession() error {
- if BConfig.WebConfig.Session.SessionOn {
- var err error
- sessionConfig := AppConfig.String("sessionConfig")
- conf := new(session.ManagerConfig)
- if sessionConfig == "" {
- conf.CookieName = BConfig.WebConfig.Session.SessionName
- conf.EnableSetCookie = BConfig.WebConfig.Session.SessionAutoSetCookie
- conf.Gclifetime = BConfig.WebConfig.Session.SessionGCMaxLifetime
- conf.Secure = BConfig.Listen.EnableHTTPS
- conf.CookieLifeTime = BConfig.WebConfig.Session.SessionCookieLifeTime
- conf.ProviderConfig = filepath.ToSlash(BConfig.WebConfig.Session.SessionProviderConfig)
- conf.DisableHTTPOnly = BConfig.WebConfig.Session.SessionDisableHTTPOnly
- conf.Domain = BConfig.WebConfig.Session.SessionDomain
- conf.EnableSidInHttpHeader = BConfig.WebConfig.Session.SessionEnableSidInHTTPHeader
- conf.SessionNameInHttpHeader = BConfig.WebConfig.Session.SessionNameInHTTPHeader
- conf.EnableSidInUrlQuery = BConfig.WebConfig.Session.SessionEnableSidInURLQuery
- } else {
- if err = json.Unmarshal([]byte(sessionConfig), conf); err != nil {
- return err
- }
- }
- if GlobalSessions, err = session.NewManager(BConfig.WebConfig.Session.SessionProvider, conf); err != nil {
- return err
- }
- go GlobalSessions.GC()
- }
- return nil
- }
- func registerTemplate() error {
- defer lockViewPaths()
- if err := AddViewPath(BConfig.WebConfig.ViewsPath); err != nil {
- if BConfig.RunMode == DEV {
- logs.Warn(err)
- }
- return err
- }
- return nil
- }
- func registerAdmin() error {
- if BConfig.Listen.EnableAdmin {
- go beeAdminApp.Run()
- }
- return nil
- }
- func registerGzip() error {
- if BConfig.EnableGzip {
- context.InitGzip(
- AppConfig.DefaultInt("gzipMinLength", -1),
- AppConfig.DefaultInt("gzipCompressLevel", -1),
- AppConfig.DefaultStrings("includedMethods", []string{"GET"}),
- )
- }
- return nil
- }
|