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

Golang middleware.Gzip函数代码示例

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

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



在下文中一共展示了Gzip函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Start

//	启动服务
func Start() {

	e := echo.New()

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

	//	注册路由
	registerRoute(e)

	log.Printf("启动Http服务,端口:%d", config.Get().Port)
	// Start server
	e.Run(fmt.Sprintf(":%d", config.Get().Port))
}
开发者ID:ifzz,项目名称:stockrecorder,代码行数:17,代码来源:server.go


示例17: New

func New() *echo.Echo {
	server = echo.New()

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

	// Serve index
	server.Index("static/index.html")

	// Static Files
	server.Static("/js", "static/js")
	server.Static("/css", "static/css")
	server.Static("/img", "static/img")

	return server
}
开发者ID:BasalticStudio,项目名称:Walrus-vs-Slime,代码行数:18,代码来源:server.go


示例18: Run

func Run(host string, port int) {
	s := echo.New()
	s.SetLogLevel(glog.FATAL)
	s.Use(echologrus.New(), middleware.Recover(), middleware.Gzip())
	s.SetRenderer(NewRenderer())
	s.Get("/assets/*", http.FileServer(
		&assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo}))
	s.Get("/data/*", http.FileServer(
		&assetfs.AssetFS{Asset: govatar.Asset, AssetDir: govatar.AssetDir, AssetInfo: govatar.AssetInfo}))

	s.Get("/", index)
	s.Get("/settings", settings)
	s.Post("/download", download)

	addr := fmt.Sprintf("%s:%d", host, port)
	log.Infof("Starting server on %s", addr)
	s.Run(addr)
}
开发者ID:o1egl,项目名称:govatar,代码行数:18,代码来源:server.go


示例19: main

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

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

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

	//open debug
	e.SetDebug(true)

	//start server
	e.Run(":1234")
}
开发者ID:jimwei,项目名称:photoswall,代码行数:18,代码来源:main.go


示例20: main

func main() {
	mongoURL := flag.String("mongodb", "mongodb://localhost/watch", "MongoDB connection URL")
	addr := flag.String("http", ":8080", "Server address & port")
	docker := flag.Bool("docker", false, "for docker")
	flag.Parse()

	// Если запускается внутри контейнера
	if *docker {
		tmp := os.Getenv("MONGODB")
		mongoURL = &tmp
	}

	mdb, err := mongo.Connect(*mongoURL)
	if err != nil {
		log.Println("Error connecting to MongoDB:", err)
		return
	}
	defer mdb.Close()

	// инициализируем хранилище с информацией о треках
	tracksDB, err = tracks.InitDB(mdb)
	if err != nil {
		log.Println("Error initializing TrackDB:", err)
		return
	}
	// инициализируем хранилище с информацией о местах
	placesDB, err = places.InitDB(mdb)
	if err != nil {
		log.Println("Error initializing PlaceDB:", err)
		return
	}

	e := echo.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Gzip())
	e.SetRenderer(&Template{templates: template.Must(
		template.ParseFiles("index.html", "current.html", "history.html"))})
	e.Get("/", index)
	e.Get("/:deviceid", current)
	e.Get("/:deviceid/history", history)
	e.ServeFile("/edit", "placeeditor.html")
	e.Run(*addr)
}
开发者ID:jtprog,项目名称:geotrack,代码行数:44,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang middleware.Logger函数代码示例发布时间:2022-05-23
下一篇:
Golang standard.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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