mirror of https://github.com/jlelse/GoBlog
Add profile middleware
This commit is contained in:
parent
601c57169a
commit
2e358e2de8
|
@ -20,6 +20,7 @@ type config struct {
|
||||||
|
|
||||||
type configServer struct {
|
type configServer struct {
|
||||||
Logging bool `mapstructure:"logging"`
|
Logging bool `mapstructure:"logging"`
|
||||||
|
Debug bool `mapstructure:"Debug"`
|
||||||
Port int `mapstructure:"port"`
|
Port int `mapstructure:"port"`
|
||||||
Domain string `mapstructure:"domain"`
|
Domain string `mapstructure:"domain"`
|
||||||
PublicAddress string `mapstructure:"publicAddress"`
|
PublicAddress string `mapstructure:"publicAddress"`
|
||||||
|
@ -133,6 +134,7 @@ func initConfig() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
viper.SetDefault("server.logging", false)
|
viper.SetDefault("server.logging", false)
|
||||||
|
viper.SetDefault("server.debug", false)
|
||||||
viper.SetDefault("server.port", 8080)
|
viper.SetDefault("server.port", 8080)
|
||||||
viper.SetDefault("server.publicAddress", "http://localhost:8080")
|
viper.SetDefault("server.publicAddress", "http://localhost:8080")
|
||||||
viper.SetDefault("server.publicHttps", false)
|
viper.SetDefault("server.publicHttps", false)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
server:
|
server:
|
||||||
logging: false
|
logging: false
|
||||||
|
debug: false
|
||||||
port: 8080
|
port: 8080
|
||||||
domain: example.com
|
domain: example.com
|
||||||
publicAddress: http://localhost:8080
|
publicAddress: http://localhost:8080
|
||||||
|
|
5
http.go
5
http.go
|
@ -63,6 +63,11 @@ func buildHandler() (http.Handler, error) {
|
||||||
}
|
}
|
||||||
r.Use(middleware.Recoverer, middleware.StripSlashes, middleware.GetHead)
|
r.Use(middleware.Recoverer, middleware.StripSlashes, middleware.GetHead)
|
||||||
|
|
||||||
|
// Profiler
|
||||||
|
if appConfig.Server.Debug {
|
||||||
|
r.Mount("/debug", middleware.Profiler())
|
||||||
|
}
|
||||||
|
|
||||||
// API
|
// API
|
||||||
r.Route("/api", func(apiRouter chi.Router) {
|
r.Route("/api", func(apiRouter chi.Router) {
|
||||||
apiRouter.Use(middleware.BasicAuth("API", map[string]string{
|
apiRouter.Use(middleware.BasicAuth("API", map[string]string{
|
||||||
|
|
Loading…
Reference in New Issue