當前位置: 首頁>>代碼示例>>Golang>>正文


Golang middleware.Gzip函數代碼示例

本文整理匯總了Golang中github.com/labstack/echo/middleware.Gzip函數的典型用法代碼示例。如果您正苦於以下問題:Golang Gzip函數的具體用法?Golang Gzip怎麽用?Golang Gzip使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Gzip函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {

	loggerService.FileHandle = "server.go"
	loggerService.ErrMsg = string("init server.go")
	loggerService.Count = len("init server.go")
	loggerService.Level = "DEBUG"
	gLoggerService.LogInit(loggerService)
	go putEnginePoll()
	// Echo instance
	e := echo.New()

	// Debug mode
	e.Debug()

	// Middleware
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.Gzip())

	// Routes
	e.Get("/expressListUsers", expressListUsers)
	e.Post("/expressEmailMessage", expressEmailMessage)
	e.Post("/expressQueryUsers", expressQueryUsers)
	e.Post("/expressTake", expressTake)
	e.Get("/expressTakeUser", expressTakeUser)

	loggerService.FileHandle = "server.go"
	loggerService.ErrMsg = string("1323 succ server.go")
	loggerService.Count = len("1323 succ server.go")
	loggerService.Level = "DEBUG"
	gLoggerService.LogInit(loggerService)
	// Start server
	e.Run(":1323")
}
開發者ID:aslijiasheng,項目名稱:jasongo,代碼行數:34,代碼來源:server.go

示例2: main

func main() {
	// Echo instance
	e := echo.New()

	// Debug mode
	e.Debug()

	//------------
	// Middleware
	//------------

	// Logger
	e.Use(mw.Logger())

	// Recover
	e.Use(mw.Recover())

	// Basic auth
	e.Use(mw.BasicAuth(func(usr, pwd string) bool {
		if usr == "joe" && pwd == "secret" {
			return true
		}
		return false
	}))

	// Gzip
	e.Use(mw.Gzip())

	// Routes
	e.Get("/", hello)

	// Start server
	e.Run(":1323")
}
開發者ID:prabirshrestha,項目名稱:echo,代碼行數:34,代碼來源:server.go

示例3: Init

func Init() *echo.Echo {

	e := echo.New()

	e.Debug()

	// Set Bundle MiddleWare
	e.Use(echoMw.Logger())
	e.Use(echoMw.Gzip())
	e.Use(echoMw.CORSWithConfig(echoMw.CORSConfig{
		AllowOrigins: []string{"*"},
		AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAcceptEncoding},
	}))
	e.SetHTTPErrorHandler(handler.JSONHTTPErrorHandler)

	// Set Custom MiddleWare
	e.Use(myMw.TransactionHandler(db.Init()))

	// Routes
	v1 := e.Group("/api/v1")
	{
		v1.POST("/members", api.PostMember())
		v1.GET("/members", api.GetMembers())
		v1.GET("/members/:id", api.GetMember())
	}
	return e
}
開發者ID:eurie-inc,項目名稱:echo-sample,代碼行數:27,代碼來源:router.go

示例4: setup

// setup prepares the internal HTTP handle, middleware, and resources.
func (s *Server) setup() {
	e := echo.New()
	s.core = e

	// Enable HTTP 2
	e.HTTP2(true)

	// Toggle debug
	e.SetDebug(s.Debug)

	// Setup middleware.
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.Gzip())

	// Setup CORS.
	e.Use(cors.New(cors.Options{
		AllowedOrigins: s.AllowedHosts,
	}).Handler)

	// Add middleware for setting the server context.
	e.Use(s.serverContext)

	e.Get("/", httpRoot)
	e.Get("/domains", httpDomains)

	e.Get("/log/:domain", httpLog)
	e.Get("/log/:domain/entities", httpDomainEntities)
	e.Get("/log/:domain/attributes", httpDomainAttributes)
	e.Get("/log/:domain/values", httpDomainValues)

	e.Get("/timeline/:domain", httpTimeline)
}
開發者ID:glycerine,項目名稱:origins,代碼行數:34,代碼來源:main.go

示例5: server

func server(config config, db *sql.DB) *echo.Echo {
	dbx := sqlx.NewDb(db, "postgres")
	exec := echo.New()
	if !config.Production {
		exec.Debug()
	}
	exec.Use(mw.Logger())
	exec.Use(mw.Recover())
	exec.Use(mw.Gzip())

	exec.Get("/status", func(c *echo.Context) error {
		return c.NoContent(http.StatusOK)
	})

	leadHandler := lead.NewHandler(datastores.NewLead(dbx))

	exec.Post("/lead", leadHandler.Create)
	exec.Get("/lead/:hashCode", leadHandler.CountByInvites)

	assetHandler := http.FileServer(rice.MustFindBox("static").HTTPBox())
	exec.Get("/", func(c *echo.Context) error {
		assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
		return nil
	})
	exec.Get("/static/*", func(c *echo.Context) error {
		http.StripPrefix("/static/", assetHandler).
			ServeHTTP(c.Response().Writer(), c.Request())
		return nil
	})

	return exec
}
開發者ID:Xmio,項目名稱:intented,代碼行數:32,代碼來源:main.go

示例6: main

func main() {
	//runtime.GOMAXPROCS(runtime.NumCPU())
	e := echo.New()

	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.Gzip())

	e.Get("/", welcome)
	e.Get("/ping", ping)

	//// Start server
	//e.Run(":1323")

	// Get the http.Server
	s := e.Server(":8000")

	// HTTP2 is currently enabled by default in echo.New(). To override TLS handshake errors
	// you will need to override the TLSConfig for the server so it does not attempt to validate
	// the connection using TLS as required by HTTP2
	s.TLSConfig = nil

	// Serve it like a boss
	log.Fatal(gracehttp.Serve(s))
}
開發者ID:itang,項目名稱:gomonkey,代碼行數:25,代碼來源:server.go

示例7: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	fetchFeed()

	e := echo.New()
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.StripTrailingSlash())
	e.Use(mw.Gzip())
	e.Use(cors.Default().Handler)

	bundle, _ := ioutil.ReadFile("./build/bundle.js")

	// stats
	s := stats.New()
	e.Use(s.Handler)
	e.Get("/stats", func(c *echo.Context) error {
		return c.JSON(http.StatusOK, s.Data())
	})
	// static files
	e.Static("/public/css", "public/css")
	e.Static("/universal.js", "./build/bundle.js")
	e.Favicon("public/favicon.ico")

	e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), rss))
	e.Get("/about", selfjs.New(runtime.NumCPU(), string(bundle), loremJSON()))

	e.Get("/api/data", apiFrontPage)
	e.Get("/api/anotherpage", apiAnotherPage)
	go tick()
	fmt.Println("serving at port 3000")
	e.Run(":3000")
}
開發者ID:jelinden,項目名稱:go-isomorphic-react-v8,代碼行數:33,代碼來源:main.go

示例8: main

func main() {
	echo_serve := echo.New()

	mws := []echo.Middleware{mw.Logger(), mw.Recover(), mw.Gzip()}
	//注冊日誌、故障恢複、響應Gzip壓縮中間件
	echo_serve.Use(mws...)

	//	echo_serve.Static("/","templates")
	//	echo_serve.Static("/js","sources/scripts")
	//	echo_serve.Static("/css","sources/css")
	//
	//	echo_serve.Index("templates/index.html")

	tmpl, err := template.ParseGlob("templates/*.html")
	if err != nil {
		fmt.Print(err.Error())
	}

	t := &Template{
		templates: template.Must(tmpl, err),
	}
	echo_serve.SetRenderer(t)
	echo_serve.Get("/hello", Hello)

	echo_serve.Run(":9060")
}
開發者ID:salJoker,項目名稱:59593364,代碼行數:26,代碼來源:main.go

示例9: main

func main() {
	fromEmail = os.Getenv("FROMEMAIL")
	emailSendingPasswd = os.Getenv("EMAILSENDINGPASSWD")
	if fromEmail == "" || emailSendingPasswd == "" {
		log.Fatal("FROMEMAIL or EMAILSENDINGPASSWD was not set")
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
	app := NewApplication()
	app.Init()
	e := echo.New()

	e.Use(middleware.HttpLogger())
	e.HTTP2()
	e.SetHTTPErrorHandler(app.errorHandler)
	e.Use(mw.Recover())
	e.Use(mw.Gzip())
	e.StripTrailingSlash()
	e.Use(cors.Default().Handler)
	/* TODO: logs too much
	newrelickey, found := os.LookupEnv("NEWRELICKEY")
	if found == true {
		gorelic.InitNewRelicAgent(newrelickey, "go-register-login", true)
		e.Use(gorelic.Handler())
	}
	*/
	s := stats.New()
	e.Use(s.Handler)

	e.Get("/stats", func(c *echo.Context) error {
		return c.JSON(http.StatusOK, s.Data())
	})

	e.Favicon("public/favicon.ico")
	e.Static("/public/css", "public/css")
	e.Static("/universal.js", "./build/bundle.js")

	bundle, _ := ioutil.ReadFile("./build/bundle.js")
	user, _ := json.Marshal(domain.User{})

	e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), string(user)))
	e.Get("/register", selfjs.New(runtime.NumCPU(), string(bundle), string(user)))
	e.Get("/login", selfjs.New(runtime.NumCPU(), string(bundle), string(user)))

	admin := e.Group("/members")
	admin.Use(middleware.CheckAdmin(app.Redis, string(bundle)))
	admin.Get("", selfjs.New(runtime.NumCPU(), string(bundle), app.listUsers()))

	e.Get("/api/users", app.listUsersAPI)
	e.Get("/api/user/:id", app.userAPI)
	e.Get("/verify/:id/:hash", app.verifyEmail)
	e.Post("/register", app.createUser)
	e.Get("/logout", app.logout)
	e.Post("/login", app.login)
	fmt.Println("Starting server at port 3300")
	e.Run(":3300")
}
開發者ID:JC1738,項目名稱:go-react-seed,代碼行數:56,代碼來源:server.go

示例10: main

func main() {
	e := echo.New()
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.Gzip())

	e.Static("/", "public")

	e.Run(":5091")
}
開發者ID:jameswei,項目名稱:kingtask,代碼行數:10,代碼來源:server.go

示例11: StartHTTP

// StartHTTP listens on the configured ports for the REST application
func (s *Service) StartHTTP() error {
	address := fmt.Sprintf("%s:%d", s.config.Interface, s.config.Port)

	URL = address
	// Use middlewares
	s.Router.Use(mw.Gzip())
	s.Router.Use(mw.Logger())
	s.Router.Run(standard.New(address))

	return nil
}
開發者ID:efimovalex,項目名稱:EventKitAPI,代碼行數:12,代碼來源:app.go

示例12: createMux

func createMux() *echo.Echo {
	e := echo.New()

	e.Use(middleware.Recover())
	e.Use(middleware.Logger())
	e.Use(middleware.Gzip())

	e.Static("/", "public")

	return e
}
開發者ID:luizbafilho,項目名稱:fusis,代碼行數:11,代碼來源:app-standalone.go

示例13: createMux

func createMux() *echo.Echo {
	e := echo.New()

	e.Use(middleware.Recover())
	e.Use(middleware.Logger())
	e.Use(middleware.Gzip())

	e.Index("public/index.html")
	e.Static("/public", "public")

	return e
}
開發者ID:prabirshrestha,項目名稱:echo,代碼行數:12,代碼來源:app-standalone.go

示例14: initApp

func initApp() *echo.Echo {
	// create router and stats handler
	e := echo.New()

	// why not, it's fast and "the future" ...
	e.HTTP2(true)

	// add middleware
	e.Use(
		middleware.Recover(),
		middleware.Logger(),
		middleware.Gzip())
	return e
}
開發者ID:gkarwchan,項目名稱:GoAngularBrowserifyBoilerplate,代碼行數:14,代碼來源:app.go

示例15: main

func main() {
	e := echo.New()
	e.StripTrailingSlash()
	e.Use(middleware.Logger())
	e.Use(middleware.Gzip())
	e.Use(middleware.Recover())
	e.Use(cors.Default().Handler)

	e.Get("/user", getHandlerFunc(models.GetUsers))
	e.Get("/store", getHandlerFunc(models.GetStores))
	e.Get("/deal", getHandlerFunc(models.GetDeals))

	e.Run(":3000")
}
開發者ID:ktsimpso,項目名稱:holla_holla_server,代碼行數:14,代碼來源:server.go


注:本文中的github.com/labstack/echo/middleware.Gzip函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。