github.com/blend/go-sdk@v1.20220411.3/examples/web/logging/main.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"context"
    12  
    13  	"github.com/blend/go-sdk/graceful"
    14  	"github.com/blend/go-sdk/logger"
    15  	"github.com/blend/go-sdk/web"
    16  	"github.com/blend/go-sdk/webutil"
    17  )
    18  
    19  func main() {
    20  	log := logger.Prod()
    21  	app := web.MustNew(web.OptLog(log))
    22  	app.GET("/", func(r *web.Ctx) web.Result {
    23  		return web.Text.Result("foo")
    24  	})
    25  	log.Listen(webutil.FlagHTTPRequest, logger.DefaultListenerName, webutil.NewHTTPRequestEventListener(func(_ context.Context, wre webutil.HTTPRequestEvent) {
    26  		log.Infof("got a new request at route: %s", wre.Route)
    27  	}))
    28  
    29  	graceful.Shutdown(app)
    30  }