本文整理汇总了Golang中github.com/labstack/echo/middleware.Logger函数的典型用法代码示例。如果您正苦于以下问题:Golang Logger函数的具体用法?Golang Logger怎么用?Golang Logger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Logger函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// Host map
hosts := make(Hosts)
//-----
// API
//-----
api := echo.New()
api.Use(mw.Logger())
api.Use(mw.Recover())
hosts["api.localhost:1323"] = api
api.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "API")
})
//------
// Blog
//------
blog := echo.New()
api.Use(mw.Logger())
api.Use(mw.Recover())
hosts["blog.localhost:1323"] = blog
blog.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Blog")
})
//---------
// Website
//---------
site := echo.New()
site.Use(mw.Logger())
site.Use(mw.Recover())
hosts["localhost:1323"] = site
site.Get("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Welcome!")
})
http.ListenAndServe(":1323", hosts)
}
开发者ID:xyproto,项目名称:echo,代码行数:48,代码来源:server.go
示例2: NewRoutes
// NewRoutes return routes
func NewRoutes() *echo.Echo {
bansaku := echo.New()
bansaku.Static("/js", "static/js")
bansaku.Static("/css", "static/css/bansaku")
bansaku.Static("/sound", "static/sound")
bansaku.Static("/font", "static/font")
bansaku.Use(mw.Logger())
bansaku.Use(mw.Recover())
t := p.PrepareTemplates(p.Options{
Directory: "templates/",
Extensions: []string{".tpl"},
})
bansaku.SetRenderer(t)
// Debug
bansaku.SetDebug(true)
server := controllers.NewBansakuServer()
go server.Start()
bansaku.Get("/", controllers.BansakuIndex)
bansaku.WebSocket("/ws", server.BansakuSocketHandler())
// API
api := bansaku.Group("/api")
api.Static("/css", "static/css/api")
api.Get("/", controllers.APIReferenceHandler)
api.Get("/count", controllers.APIBansakuGetHandler)
return bansaku
}
开发者ID:Rompei,项目名称:zepher-bansaku,代码行数:30,代码来源:routes.go
示例3: 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
示例4: main
func main() {
demoData := Data{
Id: 5,
Name: "User name",
Tags: []string{"people", "customer", "developer"},
}
e := echo.New()
e.SetDebug(true)
e.Use(middleware.Logger())
e.Use(middleware.Recover())
s := stats.New()
e.Use(standard.WrapMiddleware(s.Handler))
e.GET("/xml", func(c echo.Context) error {
return c.XML(200, demoData)
})
e.GET("/json", func(c echo.Context) error {
return c.JSON(200, demoData)
})
e.GET("/error", func(c echo.Context) error {
return echo.NewHTTPError(500, "Error here")
})
e.Run(standard.New(":8888"))
}
开发者ID:plumbum,项目名称:go-samples,代码行数:31,代码来源:main.go
示例5: main
func main() {
var (
listen = flag.String("listen", ":3000", "listen address of the application")
env = flag.String("env", "dev", "application environment")
)
flag.Parse()
// set the flags into env vars
os.Setenv("APP_ENV", *env)
// initialize database connection, with the credentials from the environment.
repo, err := database.Connect()
if err != nil {
panic(err)
}
// repo configuration
repo.LogMode(true)
// application configuration
router := echo.New()
router.SetHTTPErrorHandler(errorHandler)
router.Use(middleware.Logger(), middleware.Recover())
registerAuthHandlers(router, handler.AuthService{})
// V1 API endpoints
v1 := router.Group("/v1")
registerUserHandlers(v1, handler.UserService{repo})
router.Run(*listen)
}
开发者ID:twanies,项目名称:gonzo,代码行数:33,代码来源:main.go
示例6: main
func main() {
// Parse command line arguments
kingpin.Version("0.0.1")
kingpin.Parse()
// Prepare (optionally) embedded resources
templateBox := rice.MustFindBox("template")
staticHTTPBox := rice.MustFindBox("static").HTTPBox()
staticServer := http.StripPrefix("/static/", http.FileServer(staticHTTPBox))
e := echo.New()
t := &Template{
templates: template.Must(template.New("base").Parse(templateBox.MustString("base.html"))),
}
e.SetRenderer(t)
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET("/static/*", standard.WrapHandler(staticServer))
edit := e.Group("/edit")
edit.Get("/*", EditHandler)
edit.Post("/*", EditHandlerPost)
go WaitForServer()
e.Run(standard.New(fmt.Sprintf("127.0.0.1:%d", *args.Port)))
}
开发者ID:nochso,项目名称:gomd,代码行数:29,代码来源:gomd.go
示例7: main
func main() {
conf.Server = env("SERVER", "127.0.0.1")
conf.Password = env("PASSWORD", "ItsPass1942+")
conf.User = env("USER", "Administrator")
conf.SSHPort = env("SSH_PORT", "22")
conf.instDir = os.Getenv("INSTALLATION_DIR")
if len(conf.instDir) == 0 {
conf.instDir = "/var/lib/nanocloud"
}
conf.artURL = os.Getenv("ARTIFACT_URL")
if len(conf.artURL) == 0 {
conf.artURL = "http://releases.nanocloud.org:8080/releases/latest/"
}
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
h := handler{
iaasCon: iaas.New(conf.Server, conf.Password, conf.User, conf.SSHPort, conf.instDir, conf.artURL),
}
e.Get("/api/iaas", h.ListRunningVM)
e.Post("/api/iaas/:id/stop", h.StopVM)
e.Post("/api/iaas/:id/start", h.StartVM)
e.Post("/api/iaas/:id/download", h.DownloadVM)
e.Run(":8080")
}
开发者ID:MeoBlodnasir,项目名称:community,代码行数:34,代码来源:main.go
示例8: main
func main() {
// Check for a linked MongoDB container if we are running in Docker
mongoHost := os.Getenv("MONGO_PORT_27017_TCP_ADDR")
if mongoHost == "" {
mongoHost = "localhost"
}
registerURL := flag.String("registerURL", "", "Register a FHIR Subscription to the specified URL")
registerENV := flag.String("registerENV", "", "Register a FHIR Subscription to the the Docker environment variable IE_PORT_3001_TCP*")
flag.Parse()
parsedURL := *registerURL
if parsedURL != "" {
registerServer(parsedURL)
}
if registerENV != nil {
registerServer(fmt.Sprintf("http://%s:%s", os.Getenv("IE_PORT_3001_TCP_ADDR"), os.Getenv("IE_PORT_3001_TCP_PORT")))
}
e := echo.New()
session, err := mgo.Dial(mongoHost)
if err != nil {
panic("Can't connect to the database")
}
defer session.Close()
basePieURL := discoverSelf() + "pies"
db := session.DB("riskservice")
svc := service.NewReferenceRiskService(db)
svc.RegisterPlugin(assessments.NewCHA2DS2VAScPlugin())
svc.RegisterPlugin(assessments.NewSimplePlugin())
fnDelayer := server.NewFunctionDelayer(3 * time.Second)
server.RegisterRoutes(e, db, basePieURL, svc, fnDelayer)
e.Use(middleware.Logger())
e.Run(":9000")
}
开发者ID:intervention-engine,项目名称:riskservice,代码行数:34,代码来源:server.go
示例9: GetWebService
// GetWebService return a new gin.Engine
func GetWebService(store storage.Storage, auth *Authentication) *echo.Echo {
log.Printf("[DEBUG] [abraracourcix] Creating web service using %v",
store)
ws := v1.NewWebService(store)
e := echo.New()
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.Get("/", ws.Help())
e.Get("/:url", ws.Redirect())
e.Get("/api/version", ws.DisplayAPIVersion())
v1 := e.Group("/api/v1")
if auth != nil {
log.Printf("[INFO] [abraracourcix] Setup secure mode : %v", auth)
v1.Use(middleware.BasicAuth(func(user string, pwd string) bool {
if user == auth.Username && pwd == auth.Password {
return true
}
return false
}))
}
v1.Get("/urls/:url", ws.URLShow())
v1.Post("/urls", ws.URLCreate())
v1.Get("/stats/:url", ws.URLStats())
return e
}
开发者ID:nlamirault,项目名称:abraracourcix,代码行数:28,代码来源:handlers.go
示例10: main
func main() {
module = nano.RegisterModule("router")
setupDb()
conf.UploadDir = env("UPLOAD_DIR", "uploads/")
handler := httpHandler{
URLPrefix: "/api",
Module: module,
}
go module.Listen()
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
frontDir := env("FRONT_DIR", "front/")
e.Static("/", frontDir)
e.Get("/api/me", getMeHandler)
e.Get("/api/version", getVersionHandler)
e.Any("/api/*", handler.ServeHTTP)
e.Any("/oauth/*", oauthHandler)
e.Post("/upload", uploadHandler)
e.Get("/upload", checkUploadHandler)
addr := ":" + env("PORT", "8080")
module.Log.Info("Server running at ", addr)
e.Run(addr)
}
开发者ID:Gentux,项目名称:nanocloud-old,代码行数:30,代码来源:main.go
示例11: Handler
func (api *ApiEcho) Handler() http.Handler {
// Echo instance
e := echo.New()
// Middleware
e.Use(mw.Logger())
e.Use(mw.Recover())
// Serve static files
e.Static("/", "./public")
// stats https://github.com/thoas/stats
s := stats.New()
e.Use(s.Handler)
e.Get("/stats", func(c *echo.Context) error {
return c.JSON(http.StatusOK, s.Data())
})
// ping
e.Get("/ping", pingHandler())
// Set RGB
e.Get("/rgb/:rgb", rgbHandler(api))
// SetStabilization
e.Get("/stable/:bool", stableHandler(api))
// SetBackLED
e.Get("/backled/:level", backLedHandler(api))
// SetHeading
e.Get("/heading/:heading", headingHandler(api))
// Roll
e.Get("/roll/:speed/head/:heading", rollHandler(api))
// SetRotationRate
e.Get("/rotate_rate/:level", rotationRateHandler(api))
return e
}
开发者ID:kerkerj,项目名称:gtg15-demo,代码行数:35,代码来源:api.go
示例12: 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
示例13: main
func main() {
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
aws_config := aws.NewConfig()
skipp3r = Skipp3r{
Bucket: bucket,
Prefix: prefix,
Version: version,
Svc: s3.New(aws_config),
}
switch cmd {
case get.FullCommand():
res := skipp3r.get(getPath)
fmt.Println(res)
case set.FullCommand():
err := skipp3r.set(srcPath, destPath, doDelete)
fmt.Println(err)
case daemon.FullCommand():
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Get("/", getHandler)
e.Get("/:path", getHandler)
e.Run(":" + *port)
}
}
开发者ID:AlexThurston,项目名称:skipp3r,代码行数:30,代码来源:main.go
示例14: 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
示例15: 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
示例16: registerMiddlewares
func (as ApiService) registerMiddlewares() {
// Middlewares
as.echo.HTTPErrorHandler = CustomHTTPErrorHandler
as.echo.Use(middleware.Logger())
as.echo.Use(middleware.Recover())
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:7,代码来源:api.go
示例17: main
func main() {
port := "8080"
e := echo.New()
e.SetDebug(true)
e.Use(mw.Logger())
e.Use(mw.Recover())
e.StripTrailingSlash()
assetHandler := http.FileServer(assetFS())
e.Get("/clicks", buttonsStateHandler)
e.Post("/click/:button", buttonClicker)
e.WebSocket("/ws", socketHandler)
e.Get("/*", func(c *echo.Context) error {
assetHandler.ServeHTTP(c.Response().Writer(), c.Request())
return nil
})
// Start the "message hub"
go hub.Run()
// Detect clicks on buttons
btns = newButtons()
defer btns.Close()
btns.Run()
// Control the leds based on clicks
newLeds(btns, hub)
// Start server
log.Println("Starting server on port " + port)
graceful.ListenAndServe(e.Server(":"+port), 2*time.Second)
}
开发者ID:fgrehm,项目名称:pucrs-iot-experiment,代码行数:35,代码来源:main.go
示例18: main
func main() {
e := echo.New()
e.Use(mw.Logger())
e.Use(mw.Recover())
e.Static("/", "public")
e.WebSocket("/ws", func(c *echo.Context) (err error) {
ws := c.Socket()
msg := ""
for {
if err = websocket.Message.Send(ws, "Hello, Client!"); err != nil {
return
}
if err = websocket.Message.Receive(ws, &msg); err != nil {
return
}
println(msg)
}
return
})
e.Run(":1323")
}
开发者ID:ZhiqinYang,项目名称:echo,代码行数:25,代码来源:server.go
示例19: Start
//Start метод запускает веб-интерфейс
func (mw *ManagerWeb) Start() error {
go func() {
if mw.e == nil {
mw.e = echo.New()
}
mw.e.Use(mid.Logger()) // выводить лог
//mw.e.Use(mid.Recover()) // игнорировать ошибки при работе сервера
mw.e.Get("/", hello) // будущая основная страница
//api
mw.e.Get("/api/bots", listBot) // вывести json-список текущих ботов
mw.e.Post("/api/bots", createBot) // создать нового бота
mw.e.Patch("/api/bot/:id/:action", sendActionToBot) // отправить основные команды боту (старт, стоп...)
mw.e.Delete("/api/bot/:id", deleteBot) // удалить бота
//websocket
mw.e.WebSocket("/bots/ws", mw.websockDataBots) // вебсокет для динамического обновления информация по списку ботов
// служебные вызовы на время разработки
mw.e.Get("/api/bots/upd", mw.updateInfBots) // иницировать обновление информации в списке ботов
// TODO инициализация настроек сервера (ip с которых можно принимать запросы, порт и т.д.)
mw.e.Run(":8080")
}()
return nil
}
开发者ID:Dremalka,项目名称:SkynetPW_old,代码行数:30,代码来源:managerweb.go
示例20: 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
注:本文中的github.com/labstack/echo/middleware.Logger函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论