本文整理匯總了Golang中github.com/go-macaron/gzip.Gziper函數的典型用法代碼示例。如果您正苦於以下問題:Golang Gziper函數的具體用法?Golang Gziper怎麽用?Golang Gziper使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Gziper函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: initRouters
func initRouters() {
m.Get("/$qrcode", routers.Qrcode)
m.Get("/*", routers.NewStaticHandler(gcfg.root))
m.Post("/*", routers.NewUploadHandler(gcfg.root))
m.Get("/$zip/*", routers.NewZipDownloadHandler(gcfg.root))
m.Get("/$plist/*", routers.NewPlistHandler(gcfg.root))
m.Get("/$ipaicon/*", routers.NewIpaIconHandler(gcfg.root))
m.Get("/$ipa/*", routers.IPAHandler)
ReloadProxy := func(w http.ResponseWriter, r *http.Request) {
log.Println("Debug, Hot reload", r.Host)
resp, err := http.Get("http://localhost:3000" + r.RequestURI)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
defer resp.Body.Close()
io.Copy(w, resp.Body)
}
// HTTP Basic Authentication
userpass := strings.SplitN(gcfg.httpauth, ":", 2)
if len(userpass) == 2 {
user, pass := userpass[0], userpass[1]
m.Use(auth.Basic(user, pass))
}
if gcfg.gzip {
m.Use(gzip.Gziper())
}
m.Get("/-/:rand(.*).hot-update.:ext(.*)", ReloadProxy)
m.Get("/-/:name(.*).bundle.js", ReloadProxy)
}
示例2: init
func init() {
m = macaron.Classic()
m.Use(modules.Public)
m.Use(modules.Renderer)
m.Use(gzip.Gziper())
flag.IntVar(&gcfg.port, "port", 8000, "Which port to listen")
flag.StringVar(&gcfg.root, "root", ".", "Watched root directory for filesystem events, also the HTTP File Server's root directory")
flag.BoolVar(&gcfg.private, "private", false, "Only listen on lookback interface, otherwise listen on all interface")
flag.StringVar(&gcfg.httpauth, "auth", "", "Basic Authentication (ex: username:password)")
}
示例3: Gziper
func Gziper() macaron.Handler {
macaronGziper := gzip.Gziper()
return func(ctx *macaron.Context) {
requestPath := ctx.Req.URL.RequestURI()
// ignore datasource proxy requests
if strings.HasPrefix(requestPath, "/api/datasources/proxy") {
return
}
ctx.Invoke(macaronGziper)
}
}
示例4: init
func init() {
m = macaron.Classic()
m.Use(modules.Public)
m.Use(modules.Renderer)
m.Use(gzip.Gziper())
kingpin.HelpFlag.Short('h')
kingpin.Flag("port", "Port to listen").Default("8000").IntVar(&gcfg.port)
kingpin.Flag("root", "File root directory").Default(".").StringVar(&gcfg.root)
kingpin.Flag("private", "Only listen on loopback address").BoolVar(&gcfg.private)
kingpin.Flag("httpauth", "HTTP basic auth (ex: user:pass)").Default("").StringVar(&gcfg.httpauth)
kingpin.Flag("cert", "TLS cert.pem").StringVar(&gcfg.cert)
kingpin.Flag("key", "TLS key.pem").StringVar(&gcfg.key)
kingpin.Flag("ftp", "Enable FTP support").BoolVar(&gcfg.ftp)
kingpin.Flag("ftp-port", "FTP listen port").Default("2121").IntVar(&gcfg.ftpPort)
kingpin.Flag("ftp-auth", "FTP auth (ex: user:pass)").Default("admin:123456").StringVar(&gcfg.ftpAuth)
}
示例5: newMacaron
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
m := macaron.New()
if !setting.DisableRouterLog {
m.Use(macaron.Logger())
}
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(gzip.Gziper())
}
if setting.Protocol == setting.FCGI {
m.SetURLPrefix(setting.AppSubUrl)
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
SkipLogging: setting.DisableRouterLog,
},
))
m.Use(macaron.Static(
setting.AvatarUploadPath,
macaron.StaticOptions{
Prefix: "avatars",
SkipLogging: setting.DisableRouterLog,
},
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
Funcs: []gotmpl.FuncMap{template.Funcs},
IndentJSON: macaron.Env != macaron.PROD,
}))
localeNames, err := bindata.AssetDir("conf/locale")
if err != nil {
log.Fatal(4, "Fail to list locale files: %v", err)
}
localFiles := make(map[string][]byte)
for _, name := range localeNames {
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
}
m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl,
Files: localFiles,
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
DefaultLang: "en-US",
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
AdapterConfig: setting.CacheConn,
Interval: setting.CacheInternal,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubUrl,
}))
m.Use(session.Sessioner(setting.SessionConfig))
m.Use(csrf.Csrfer(csrf.Options{
Secret: setting.SecretKey,
SetCookie: true,
Header: "X-Csrf-Token",
CookiePath: setting.AppSubUrl,
}))
m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
Desc: "Database connection",
Func: models.Ping,
},
},
}))
m.Use(middleware.Contexter())
return m
}