本文整理匯總了Golang中github.com/gin-gonic/gin.Logger函數的典型用法代碼示例。如果您正苦於以下問題:Golang Logger函數的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Logger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setup
func setup() *gin.Engine {
runtime.GOMAXPROCS(runtime.NumCPU())
if _, err := database.InitDb(); err != nil {
panic(err)
}
app := gin.New()
app.Use(func(c *gin.Context) {
c.Set(config.SecretKey, config.GetSecret())
c.Next()
})
if config.GetEnv() == config.EnvProduction {
app.Use(middleware.Recovery())
} else {
app.Use(gin.Recovery())
}
if config.GetEnv() == config.EnvTesting {
gin.SetMode(gin.TestMode)
} else {
app.Use(gin.Logger())
}
app.Use(middleware.ErrorHandler())
//Set up api v1
routeV1(app)
return app
}
示例2: StartGin
func StartGin() {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
gin.Logger()
router.Use(rateLimit, gin.Recovery())
router.Use(gin.Logger())
router.LoadHTMLGlob("resources/*.templ.html")
router.Static("/static", "resources/static")
router.GET("/", MyBenchLogger(), index)
router.GET("/auth", authentication.RequireTokenAuthentication(), index)
router.POST("/test", controllers.Login)
router.GET("/room/:name", roomGET)
router.POST("/room-post/:roomid", roomPOST)
router.GET("/stream/:roomid", streamRoom)
//mongodb user create
uc := user_controllers.NewUserController(getSession())
router.GET("/user", uc.GetUser)
router.GET("/message", uc.GetMessage)
router.POST("/message", uc.CreateMessage)
router.POST("/user", uc.CreateUser)
router.DELETE("/user/:id", uc.RemoveUser)
router.Run(":5001")
}
示例3: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
role := config.mustGetString("postgres", "role")
database := config.mustGetString("postgres", "database")
ip := config.mustGetString("postgres", "ip")
password := config.mustGetString("postgres", "password")
services.InitDBConnection(role, password, database, ip)
api_key := config.mustGetString("parsemap", "api_key")
r := gin.New()
r.Use(gzip.Gzip(gzip.DefaultCompression))
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(gin.ErrorLogger())
v2 := r.Group("/v2")
services.GetHandlersV2(v2, api_key)
var wg sync.WaitGroup
wg.Add(2)
go startServer(r, &wg)
go startTLSServer(r, &wg)
wg.Wait()
}
示例4: Run
func Run() {
r := gin.New()
// Global middlewares
// If use gin.Logger middlewares, it send duplicated request.
switch config.Environment {
case "DEVELOPMENT":
r.Use(gin.Logger())
case "TEST":
r.Use(log.AccessLogger())
case "PRODUCTION":
r.Use(log.AccessLogger())
}
r.Use(gin.Recovery())
r.Use(CORSMiddleware())
switch config.Frontend {
case "CanJS":
canjs.LoadPage(r)
default:
canjs.LoadPage(r)
}
api.RouteAPI(r)
// Listen and server on 0.0.0.0:3001
// r.Run("localhost:3001")
r.Run(":3001")
}
示例5: main
func main() {
var errd error
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT seadmata")
}
db, errd = sql.Open("postgres", os.Getenv("DATABASE_URL"))
if errd != nil {
log.Fatalf("Viga andmebaasiga connectimisel: %q", errd)
}
router := gin.New()
router.Use(gin.Logger())
router.LoadHTMLGlob("templates/*.tmpl.html")
router.Static("/static", "static")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl.html", nil)
})
router.GET("/db", dbFunc)
router.Run(":" + port)
}
示例6: main
func main() {
err := modem.Connect()
if err != nil {
log.Printf("ConnectModem: error connecting to %s, %s\r\n", modem.DeviceId, err)
log.Printf("commport: %s\r\n", config.CommPort)
log.Printf("baud: %d\r\n", config.Baud)
os.Exit(1)
}
err = modem.InitialiseModem()
if err != nil {
log.Printf("InitModem: error initialising %s, %s\r\n", modem.DeviceId, err)
}
// Creates a router without any middleware by default
//gin.SetMode(gin.ReleaseMode)
r := gin.New()
// Global middlewares
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(SetJellyBeans())
api := r.Group("/api")
{
api.GET("/sms", index)
api.POST("/sms", sendSMS)
}
go worker()
// Listen and server on 0.0.0.0:8951
r.Run(bindaddress)
}
示例7: createRouter
func createRouter() {
r = gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(corsMiddleware)
r.Use(i18nMiddleware)
}
示例8: main
func main() {
// Set Working direcotry
_, filename, _, _ := runtime.Caller(0)
var dir, _ = filepath.Split(filename)
os.Chdir(dir)
// Echo instance
r := gin.New()
// Global middleware
r.Use(gin.Logger())
r.Use(gin.Recovery())
// Database
r.Use(config.DbMw())
// Sessions
r.Use(config.SessionMw())
// Templates
// config.SetRenderer(e)
// Routes
config.Routes(r)
// Start server
var port = ":3333"
log.Println("HTTP Server running on port :3333!")
r.Run(port)
}
示例9: Server
func Server() {
runtime.GOMAXPROCS(runtime.NumCPU())
if _, err := database.InitDb(); err != nil {
panic(err)
}
app := gin.New()
app.Use(func(c *gin.Context) {
c.Set(config.SecretKey, config.GetSecret())
c.Next()
})
if config.GetEnv() != config.EnvProduction {
app.Use(gin.Logger())
app.Use(gin.Recovery())
} else {
app.Use(middleware.Recovery())
}
app.Use(middleware.ErrorHandler())
app.Static("/public", "./public")
//Set up api v1
setupApiV1(app)
env := config.GetEnvValue()
app.Run(env.Server.Host + ":" + strconv.Itoa(env.Server.Port))
}
示例10: NewOpenVPNAuthd
// NewOpenVPNAuthd creates a new service for shipping out the openvpn config
func NewOpenVPNAuthd(cfg *AuthConfig) (OpenVPNAuthd, error) {
//var err error
glog.Infof("creating a new openvpn authd service, config: %s", cfg)
service := new(openvpnAuthd)
service.config = cfg
// step: create the vault client
glog.V(3).Infof("creating the vault client, address: %s, username: %s", cfg.VaultURL, cfg.VaultUsername)
client, err := NewVaultClient(cfg.VaultURL, cfg.VaultCaFile, cfg.VaultTLSVerify)
if err != nil {
return nil, fmt.Errorf("failed to create a vault client, error: %s", err)
}
service.vault = client
// step: attempt to authenticate to vault
err = client.Authenticate(cfg.VaultUsername, cfg.VaultPassword)
if err != nil {
return nil, fmt.Errorf("failed to authenticate to vault, error: %s", err)
}
// step: create the gin router
router := gin.New()
router.LoadHTMLGlob("templates/*")
router.Use(gin.Logger())
router.Use(gin.Recovery())
router.GET("/health", service.healthHandler)
router.GET("/", service.openVPNHandler)
service.router = router
return service, nil
}
示例11: main
func main() {
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
router := gin.New()
router.Use(gin.Logger())
router.Static("/js", "js")
router.Static("/static", "static")
router.LoadHTMLGlob("templates/*.html")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.html", nil)
})
router.GET("/pages/:page", func(c *gin.Context) {
page := fmt.Sprint(c.Params.ByName("page"), ".html")
c.HTML(http.StatusOK, page, nil)
})
router.GET("/ssbapi/:number", ssbHandler)
router.Run(":" + port)
}
示例12: main
func main() {
flag.Parse()
conf, err := loadConfiguration()
if err != nil {
log.Fatal(err)
return
}
verbose, err := strconv.ParseBool(conf.Verbose)
if err != nil {
log.Fatal(err)
return
}
airbrakeProjectID, err := strconv.ParseInt(conf.AirbrakeProjectID, 10, 64)
if err != nil {
log.Fatal(err)
return
}
airbrake = gobrake.NewNotifier(airbrakeProjectID, conf.AirbrakeProjectKey)
r := gin.New()
r.Use(airbrakeRecovery(airbrake)) // Use airbrakeRecovery as early as possible
r.Use(newrelic.NewRelic(conf.NewRelicLicenseKey, conf.DbName, verbose))
r.Use(gin.Logger())
buildRoutes(r)
r.Run(conf.BindAddress) // listen and serve
}
示例13: main
func main() {
// nuCPU := runtime.NumCPU()
// runtime.GOMAXPROCS(nuCPU)
// fmt.Printf("Running with %d CPUs\n", nuCPU)
if !configs.Debug {
gin.SetMode(gin.ReleaseMode)
}
if configs.Debug {
r.Use(gin.Logger())
}
r.Use(gin.Recovery())
r.Static("/static", "./static")
// r.LoadHTMLGlob("templates/**/*.html")
// r.GET("/", indexPageHandler)
r.GET("/", loginRequired(indexPageHandler))
r.GET(login_page, loginHandler)
r.POST(login_page, authLoginHandler)
r.POST("/logout", logoutHandler)
r.GET("/upload", loginRequired(upload))
r.POST("/upload", loginRequired(upload))
r.GET("/page/:link", pageRouter)
r.NoRoute(func(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
})
// r.Run(":8080") // listen and serve on 0.0.0.0:8080
http.ListenAndServe(":8080", CSRF(r))
// http.ListenAndServeTLS(":8080", "/etc/nginx/ssl/nginx.crt", "/etc/nginx/ssl/nginx.key", CSRF(r))
}
示例14: main
func main() {
// fire this up
router := gin.Default()
router.Use(gin.Logger())
// load the dang templates
router.LoadHTMLGlob("templates/*.html")
// router.Use(static.Serve("/static", static.LocalFile("html", false)))
router.Static("/static", "static")
// handle root
router.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "wat")
})
// check the incoming phrase
router.GET("/blink/:phrase", func(c *gin.Context) {
phrase := c.Param("phrase")
c.HTML(http.StatusOK, "main.html", gin.H{
"title": phrase,
"phrase": phrase,
"twitter_handle": "mike_dory",
"google_analytics_id": "XXXXX-XX",
})
})
// run!
router.Run(":8081")
}
示例15: main
func main() {
r = gin.Default()
// Global middleware
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Static("/assets", "./assets")
r.LoadHTMLGlob("view/*")
// Simple group: v1
v1 := r.Group("/")
{
v1.GET("/", home.Dispatch)
}
// Simple group: v2
v2 := r.Group("/api")
{
v2.GET("/login", api.Login)
v2.GET("/mail/list", api.MailList)
v2.GET("/mail/detail", api.MailDetail)
v2.GET("/mail/box", api.MailBox)
v2.GET("/mail/send", api.MailSend)
v2.GET("/mail/set", api.MailSet)
}
r.Run(":8081")
}