本文整理汇总了Golang中github.com/phyber/negroni-gzip/gzip.Gzip函数的典型用法代码示例。如果您正苦于以下问题:Golang Gzip函数的具体用法?Golang Gzip怎么用?Golang Gzip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Gzip函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RunServer
// RunServer runs the app
func RunServer() error {
cnf, db, err := initConfigDB(true, true)
if err != nil {
return err
}
defer db.Close()
if err := initServices(cnf, db); err != nil {
return err
}
// Start a classic negroni app
app := negroni.New()
app.Use(negroni.NewRecovery())
app.Use(negroni.NewLogger())
app.Use(gzip.Gzip(gzip.DefaultCompression))
app.Use(negroni.NewStatic(http.Dir("public")))
// Create a router instance
router := mux.NewRouter()
// Add routes
healthService.RegisterRoutes(router, "/v1")
oauthService.RegisterRoutes(router, "/v1/oauth")
webService.RegisterRoutes(router, "/web")
// Set the router
app.UseHandler(router)
// Run the server on port 8080, gracefully stop on SIGTERM signal
graceful.Run(":8080", 5*time.Second, app)
return nil
}
示例2: main
func main() {
// Load the configuration.
err := envconfig.Process("elwinar", &configuration)
if err != nil {
log.Fatalln("unable to read the configuration from env:", err)
}
// Open the database connection.
database, err = sqlx.Connect("sqlite3", configuration.Database)
if err != nil {
log.Fatalln("unable to open the database:", err)
}
// Initialize the router.
router := httprouter.New()
// Add the front-office handlers.
router.GET("/", Index)
router.GET("/read", List)
router.GET("/article/:slug", View)
router.GET("/fortune", Fortune)
router.GET("/sitemap.xml", Sitemap)
// Add the back-office handlers.
router.GET("/login", Login)
router.POST("/login", Authenticate)
router.GET("/logout", Logout)
router.GET("/write", Write)
router.POST("/write", Create)
router.GET("/article/:slug/edit", Edit)
router.POST("/article/:slug/edit", Update)
router.GET("/article/:slug/delete", Delete)
router.GET("/article/:slug/publish", Publish)
router.GET("/article/:slug/unpublish", Unpublish)
// Initialize the server middleware stack.
stack := negroni.New()
stack.Use(gzip.Gzip(gzip.DefaultCompression))
stack.Use(negroni.NewRecovery())
stack.Use(negroni.NewStatic(http.Dir(configuration.Public)))
stack.Use(sessions.Sessions("elwinar", cookiestore.New([]byte(configuration.Secret))))
stack.UseHandler(router)
// Initialize the HTTP server.
server := &graceful.Server{
Timeout: 1 * time.Second,
Server: &http.Server{
Addr: fmt.Sprintf(":%d", configuration.Port),
Handler: stack,
},
}
// Run the server.
err = server.ListenAndServe()
if err != nil {
log.Fatalln("unable to run the server:", err)
}
}
示例3: RunServer
// RunServer runs the app
func RunServer() error {
cnf, db, err := initConfigDB(true, true)
if err != nil {
return err
}
defer db.Close()
// Initialise the health service
healthService := health.NewService(db)
// Initialise the oauth service
oauthService := oauth.NewService(cnf, db)
// Initialise the email service
emailService := email.NewService(cnf)
// Initialise the accounts service
accountsService := accounts.NewService(
cnf,
db,
oauthService,
emailService,
nil, // accounts.EmailFactory
)
// Initialise the facebook service
facebookService := facebook.NewService(
cnf,
db,
accountsService,
nil, // facebook.Adapter
)
// Start a negroni app
app := negroni.New()
app.Use(negroni.NewRecovery())
app.Use(negroni.NewLogger())
app.Use(gzip.Gzip(gzip.DefaultCompression))
// Create a router instance
router := mux.NewRouter()
// Register routes
healthService.RegisterRoutes(router, "/v1")
oauthService.RegisterRoutes(router, "/v1/oauth")
accountsService.RegisterRoutes(router, "/v1")
facebookService.RegisterRoutes(router, "/v1/facebook")
// Set the router
app.UseHandler(router)
// Run the server on port 8080, gracefully stop on SIGTERM signal
graceful.Run(":8080", 5*time.Second, app)
return nil
}
示例4: buildMiddlewareStack
func buildMiddlewareStack(conf *Conf) *negroni.Negroni {
stack := negroni.New()
// Recover from panics and send them up to Rollbar.
stack.Use(middleware.NewRecovery())
// Gzip-compress responses if requested.
stack.Use(gzip.Gzip(gzip.DefaultCompression))
return stack
}
示例5: main
func main() {
r := mux.NewRouter()
r.HandleFunc("/"+config.Secret, WebhookHandler).Methods("POST")
http.Handle("/", r)
n := negroni.Classic()
n.Use(gzip.Gzip(gzip.DefaultCompression))
n.UseHandler(r)
n.Run(config.ListenAddress)
}
示例6: main
func main() {
router := mux.NewRouter()
router.HandleFunc("/black-and-gray", ShowCars)
n := negroni.New()
n.Use(negroni.NewLogger())
// include the gzip middleware above any other middleware that alters response body
n.Use(gzip.Gzip(gzip.DefaultCompression))
n.Use(negroni.NewRecovery())
n.Use(negroni.NewStatic(http.Dir("public")))
n.UseHandler(router)
n.Run(":8888")
}
示例7: NewApp
// NewApp returns a pointer to an application instance. These
// instances have reasonable defaults and include middleware to:
// recover from panics in handlers, log information about the request,
// and gzip compress all data. Users must specify a default version
// for new methods.
func NewApp() *APIApp {
a := &APIApp{
StrictSlash: true,
defaultVersion: -1, // this is the same as having no version prepended to the path.
port: 3000,
}
a.AddMiddleware(negroni.NewRecovery())
a.AddMiddleware(NewAppLogger())
a.AddMiddleware(gzip.Gzip(gzip.DefaultCompression))
return a
}
示例8: main
func main() {
r := render.New(render.Options{
Layout: "layout",
})
mux := httprouter.New()
mux.GET("/", func(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
r.HTML(w, http.StatusOK, "index", nil)
})
n := negroni.Classic()
n.Use(gzip.Gzip(gzip.DefaultCompression))
n.UseHandler(mux)
graceful.Run(":"+os.Getenv("PORT"), 10*time.Second, n)
}
示例9: main
func main() {
router := mux.NewRouter()
router.HandleFunc("/routes/{route}", api.Stops)
router.HandleFunc("/routes", api.AllStops)
router.HandleFunc("/vehicles/{route}", api.Vehicles)
router.HandleFunc("/vehicles", api.AllVehicles)
n := negroni.New()
n.Use(gzip.Gzip(gzip.DefaultCompression))
n.UseHandler(cors.Default().Handler(router))
go jobs.RunFetch()
go jobs.RunExpire()
n.Run(":8048")
}
示例10: New
func New() http.Handler {
// set up handlers
http.HandleFunc("/1/setpoint.json", makeHandler(setpointHandler))
http.HandleFunc("/1/sleep.json", makeHandler(sleepHandler))
http.HandleFunc("/1/smooth.json", makeHandler(smoothHandler))
http.HandleFunc("/1/setpid.json", makeHandler(setpidHandler))
http.Handle("/1/data.json", negroni.New(
gzip.Gzip(gzip.DefaultCompression),
negroni.Wrap(makeHandler(dataHandler)),
))
// use negroni
n := negroni.New(negroni.NewRecovery(), negroni.NewLogger())
n.UseHandler(http.DefaultServeMux)
return http.Handler(n)
}
示例11: RunServer
// RunServer runs the app
func RunServer() error {
cnf, db, err := initConfigDB(true, true)
defer db.Close()
if err != nil {
return err
}
// Initialise the health service
healthService := health.NewService(db)
// Initialise the oauth service
oauthService := oauth.NewService(cnf, db)
// Initialise the web service
webService := web.NewService(cnf, oauthService)
// Start a classic negroni app
app := negroni.New()
app.Use(negroni.NewRecovery())
app.Use(negroni.NewLogger())
app.Use(gzip.Gzip(gzip.DefaultCompression))
app.Use(negroni.NewStatic(http.Dir("public")))
// Create a router instance
router := mux.NewRouter()
// Add routes for the health service (healthcheck endpoint)
health.RegisterRoutes(router, healthService)
// Add routes for the oauth service (REST tokens endpoint)
oauth.RegisterRoutes(router, oauthService)
// Add routes for the web package (register, login authorize web pages)
web.RegisterRoutes(router, webService)
// Set the router
app.UseHandler(router)
// Run the server on port 8080
app.Run(":8080")
return nil
}
示例12: configRoutes
func configRoutes(dbh *db.Handle) *negroni.Negroni {
r := mux.NewRouter().PathPrefix(webroot).Subrouter()
r.HandleFunc("/api", capsHandler).Queries("t", "caps")
r.HandleFunc("/api", searchHandler).Queries("t", "search")
r.HandleFunc("/api", tvSearchHandler).Queries("t", "tvsearch")
r.HandleFunc("/getnzb", nzbDownloadHandler)
r.HandleFunc("/", homeHandler)
n := negroni.Classic()
n.Use(gzip.Gzip(gzip.DefaultCompression))
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
})
n.Use(negronilogrus.NewCustomMiddleware(logrus.DebugLevel, &logrus.JSONFormatter{}, "web"))
n.Use(c)
n.Use(dbMiddleware(dbh))
n.UseHandler(r)
return n
}
示例13: makeHandler
func makeHandler() http.Handler {
router := httprouter.New()
GET(router, "/", HandleIndex)
GET(router, "/auth/user", HandleAuthUser)
POST(router, "/auth/login", HandleLogin)
POST(router, "/auth/register", HandleRegister)
POST(router, "/auth/logout", HandleLogout)
POST(router, "/auth/stripe", Authed(HandleUpdateStripe))
POST(router, "/model/create", Authed(HandleCreateModel))
GET(router, "/user/username/:username", HandleUserByUsername)
GET(router, "/models/username/:username", HandleModelsByUsername)
GET(router, "/models/public/latest", HandleLatestPublicModels)
GET(router, "/models/public/top/:period", HandleTopPublicModels)
GET(router, "/model/username/:username/slug/:slug", HandleModelByUsernameAndSlug)
POST(router, "/model/id/:id/readme", Authed(HandleUpdateModelReadme))
POST(router, "/model/id/:id/deleted", Authed(HandleDeleteModel))
POST(router, "/file/:username/:slug/:framework/:filename", Authed(HandleFileUpload))
GET(router, "/file/:username/:slug/:framework/:filename", HandleFile)
GET(router, "/file-id/:id", HandleFileById)
GET(router, "/file-versions/:username/:slug/:framework/:filename", HandleFileVersions)
GET(router, "/model/username/:username/slug/:slug/latest-files", HandleLatestFilesByUsernameAndSlug)
n := negroni.New(negroni.NewLogger())
// In production, redirect all traffic to https (except /, for LB health check)
if utils.Conf.Production {
n.UseHandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" && r.Header.Get("X-Forwarded-Proto") != "https" {
http.RedirectHandler(
"https://"+r.Host+r.URL.RequestURI(),
http.StatusFound,
).ServeHTTP(rw, r)
}
})
}
n.Use(gzip.Gzip(gzip.BestCompression))
n.Use(negronilogrus.NewMiddleware())
n.UseHandler(router)
return n
}
示例14: Serve
func (a *API) Serve(addr string) {
router := mux.NewRouter()
v1 := router.PathPrefix("/1").Subrouter()
// tasks
tasksHandler := TasksHandler{a.store.Tasks()}
task := v1.PathPrefix("/tasks/{id}").Subrouter()
task.Methods("GET").HandlerFunc(tasksHandler.Get)
task.Methods("PUT").HandlerFunc(tasksHandler.Set)
task.Methods("DELETE").HandlerFunc(tasksHandler.Delete)
task.Methods("POST", "PATCH").HandlerFunc(MethodNotAllowed)
tasks := v1.PathPrefix("/tasks").Subrouter()
tasks.Methods("GET").HandlerFunc(tasksHandler.List)
tasks.Methods("POST").HandlerFunc(tasksHandler.Set)
tasks.Methods("PUT", "DELETE", "PATCH").HandlerFunc(MethodNotAllowed)
// events
eventsHandler := EventsHandler{a.store.Events(), a.Events}
event := v1.PathPrefix("/events/{id}").Subrouter()
event.Methods("GET").HandlerFunc(eventsHandler.Get)
event.Methods("PUT", "POST", "DELETE", "PATCH").HandlerFunc(MethodNotAllowed)
events := v1.PathPrefix("/events").Subrouter()
events.Methods("GET").HandlerFunc(eventsHandler.List)
events.Methods("POST").HandlerFunc(eventsHandler.Create)
events.Methods("PUT", "DELETE", "PATCH").HandlerFunc(MethodNotAllowed)
// set up event handlers
n := negroni.New()
n.Use(negroni.NewRecovery())
n.Use(negronilogrus.NewMiddleware())
n.Use(gzip.Gzip(gzip.DefaultCompression))
n.UseHandler(router)
logrus.WithField("addr", addr).Info("listening")
graceful.Run(addr, 10*time.Second, n)
}
示例15: main
func main() {
// Parse flags
parseFlags()
// New logger
l := log.New(os.Stdout, "[actions-store] ", 0)
// If database url is empty its a fatal error
if database == "" {
l.Fatal("Database url can not be empty. Use `-database` flag or `MONGO_URL` environment variable.")
}
// Set database url
err := models.SetDatabase(database)
if err != nil {
l.Fatal(err)
}
// Todo: authentication
n := negroni.Classic()
n.Use(negroni.HandlerFunc(corsMiddleware))
n.Use(gzip.Gzip(gzip.DefaultCompression))
// Bind actions REST api
n.UseHandler(routes.Router)
// Start JSON-RPC server
go func() {
l.Printf("rpc listening on %s", rpcaddress)
err := rpc.Listen(rpcaddress)
if err != nil {
panic(err)
}
}()
// Start HTTP server
l.Printf("listening on %s", address)
l.Fatal(http.ListenAndServe(address, n))
}