• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gzip.Gzip函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/phyber/negroni-gzip/gzip.Gzip函数的典型用法代码示例。如果您正苦于以下问题:Golang Gzip函数的具体用法?Golang Gzip怎么用?Golang Gzip使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Gzip函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:RichardKnop,项目名称:go-oauth2-server,代码行数:34,代码来源:run_server.go


示例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)
	}
}
开发者ID:chibimi,项目名称:elwinar,代码行数:58,代码来源:elwinar.go


示例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
}
开发者ID:RichardKnop,项目名称:example-api,代码行数:57,代码来源:run_server.go


示例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
}
开发者ID:brandur,项目名称:spaced,代码行数:11,代码来源:main.go


示例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)
}
开发者ID:leftees,项目名称:bownse,代码行数:11,代码来源:main.go


示例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")
}
开发者ID:esses,项目名称:accelerate,代码行数:12,代码来源:main.go


示例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
}
开发者ID:tychoish,项目名称:gimlet,代码行数:18,代码来源:app.go


示例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)
}
开发者ID:3zcurdia,项目名称:go-web-template,代码行数:15,代码来源:app.go


示例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")
}
开发者ID:K4orta,项目名称:tunnel-speed-api,代码行数:16,代码来源:main.go


示例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)
}
开发者ID:Reinaesaya,项目名称:go-cuddlebot,代码行数:17,代码来源:server.go


示例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
}
开发者ID:sotosof,项目名称:go-oauth2-server,代码行数:44,代码来源:run_server.go


示例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
}
开发者ID:hobeone,项目名称:gonab,代码行数:19,代码来源:api.go


示例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
}
开发者ID:gradientzoo,项目名称:gradientzoo,代码行数:43,代码来源:main.go


示例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)
}
开发者ID:asteris-llc,项目名称:reflex,代码行数:42,代码来源:api.go


示例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))
}
开发者ID:crackcomm,项目名称:actions-store,代码行数:39,代码来源:main.go


示例16: main

func main() {
	var httpPort = flag.Int("port", 8080, "port to listen on for HTTP")
	var dbHost = flag.String("dbhost", "localhost:27017", "host/port to connect to DB server")
	flag.Parse()

	session, err := mgo.Dial(*dbHost)
	if err != nil {
		fmt.Println(err)
		return
	}

	lk := logkeeper.New(session, logkeeper.Options{
		DB:  "buildlogs",
		URL: fmt.Sprintf("http://localhost:%v", *httpPort),
	})
	router := lk.NewRouter()
	n := negroni.Classic()
	n.Use(gzip.Gzip(gzip.DefaultCompression))
	n.UseHandler(router)

	graceful.Run(fmt.Sprintf(":%v", *httpPort), 10*time.Second, n)
}
开发者ID:tessavitabile,项目名称:logkeeper,代码行数:22,代码来源:logkeeper.go


示例17: main

func main() {
	// Load configuration
	// TODO: How to share this config with the handlers?
	configuration, err := config.Load("./config.json")
	if err != nil {
		log.Fatal(err)
	}

	// Setup middleware
	middle := negroni.Classic()
	middle.Use(gzip.Gzip(gzip.DefaultCompression))

	store := cookiestore.New([]byte("keyboard cat"))
	middle.Use(sessions.Sessions("tvtio", store))

	// Setup router
	router := httprouter.New()
	router.GET("/", routes.Index)
	router.GET("/search", routes.Search)
	router.GET("/movie/:id", routes.Movie)
	router.GET("/tv/:id", routes.TV)
	router.GET("/person/:id", routes.Person)
	router.GET("/about", routes.About)
	router.GET("/login", routes.Login)
	router.GET("/logout", routes.Logout)
	router.GET("/auth/twitter", routes.AuthTwitter)
	router.GET("/auth/facebook", routes.AuthFacebook)
	router.GET("/auth/facebook/callback", routes.AuthFacebookCallback)
	router.ServeFiles("/css/*filepath", http.Dir(configuration.Templates+"/css"))
	router.ServeFiles("/js/*filepath", http.Dir(configuration.Templates+"/js"))
	router.ServeFiles("/img/*filepath", http.Dir(configuration.Templates+"/img"))

	middle.UseHandler(router)

	// Start server
	fmt.Println("Listening at " + configuration.ServerURL())
	log.Fatal(http.ListenAndServe(configuration.ServerAddress(), middle))
}
开发者ID:josgilmo,项目名称:front,代码行数:38,代码来源:server.go


示例18: main

func main() {
	// render
	ren := render.New(render.Options{
		Layout:        "shared/layout",
		IndentJSON:    true,
		IsDevelopment: false,
	})

	//init db
	db, err := sqlx.Connect("mysql", "root:[email protected](127.0.0.1:3306)/sfs")
	if err != nil {
		log.Print(err)
		log.Print("Error initializing database...")
	}
	defer db.Close()

	// setup context
	c := ctx{db, ren}

	// setup negroni
	n := negroni.New()

	// setup router
	router := mux.NewRouter()

	// routes
	router.HandleFunc("/", c.NewSupporter).Methods("GET")
	router.HandleFunc("/", c.NewSupporterPost).Methods("POST")
	router.HandleFunc("/love", c.ShowSupporters).Methods("GET")

	//n.Use(NewRecovery(false))
	n.Use(gzip.Gzip(gzip.DefaultCompression))
	n.Use(negroni.NewStatic(http.Dir("public")))

	n.UseHandler(router)

	n.Run(fmt.Sprint(":", os.Getenv("PORT")))
}
开发者ID:travjones,项目名称:sfs,代码行数:38,代码来源:main.go


示例19: main

func main() {
	common.Initvars()
	common.Setupdb()
	// common.Setupspellchecker()
	// TODO: Setup shutdown when server is given a signal - see common.SetupShutdown
	defer common.Shutdown()
	// fmt.Println(common.Spk.SuggestSpelling("artointestinal"))
	// fmt.Println(common.Spk.CheckText("Myocariel Infraction"))

	n := negroni.Classic()
	n.Use(gzip.Gzip(gzip.DefaultCompression))
	n.Use(negroni.NewRecovery())
	n.Use(negroni.NewLogger())

	mux := http.NewServeMux()
	mux.Handle("/", http.FileServer(http.Dir(common.Siteroot)))
	mux.HandleFunc("/snomed/searchterm", handlers.Snomedsearchterm)
	mux.HandleFunc("/loinc/searchterm", handlers.Loincsearchterm)
	n.UseHandler(mux)

	fmt.Println("Ontoserver Started")
	n.Run(":80")
}
开发者ID:healthitinternals,项目名称:termsearcher,代码行数:23,代码来源:termsearcher.go


示例20: main

func main() {
	mainServer := negroni.New()

	// Token auth middleware
	tokenVerification := handlers.NewTokenVerificationMiddleware()
	tokenVerification.Initialize()
	mainServer.Use(negroni.NewRecovery())
	mainServer.Use(negroni.NewLogger())
	mainServer.Use(negroni.HandlerFunc(tokenVerification.Run))
	mainServer.Use(gzip.Gzip(gzip.DefaultCompression))

	// Create external service connections
	s := session.New()
	dynamoDBConnection := createDynamoDBConnection(s)
	geoLookup := geo.NewGoogleGeoLookup(os.Getenv("GOOGLE_API_KEY"))
	geoLookup.Initialize()
	deviceDatabase := db.NewDeviceDatabase(dynamoDBConnection, geoLookup)
	measurementsDatabase, err := createMeasurementsDatabaseConnection(deviceDatabase)
	if err != nil {
		fmt.Printf("Error connecting to InfluxDB: %s\n", err.Error())
		return
	}

	// Initialize HTTP service handlers
	router := mux.NewRouter()
	handlers.InitializeRouterForSensorsDataRetrieval(router, deviceDatabase, measurementsDatabase)
	handlers.InitializeRouterForSensorHandler(router, deviceDatabase)
	mainServer.UseHandler(router)
	go mainServer.Run(":3000")

	// Run healthcheck service
	healthCheckServer := negroni.New()
	healthCheckRouter := mux.NewRouter()
	handlers.InitializeRouterForHealthCheckHandler(healthCheckRouter, dynamoDBConnection)
	healthCheckServer.UseHandler(healthCheckRouter)
	healthCheckServer.Run(":3100")
}
开发者ID:skidder,项目名称:streammarker-data-access,代码行数:37,代码来源:data_access.go



注:本文中的github.com/phyber/negroni-gzip/gzip.Gzip函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang imageserver.ServerFunc函数代码示例发布时间:2022-05-28
下一篇:
Golang filters.Context类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap