upd(cmd/crm): update with monitor, pprof
This commit is contained in:
@@ -6,8 +6,9 @@ import (
|
||||
)
|
||||
|
||||
type configuration struct {
|
||||
httpAddr string
|
||||
dbDSN string
|
||||
httpAddr string
|
||||
dbDSN string
|
||||
monitorInterval int
|
||||
}
|
||||
|
||||
func flags(prefix string, mountFlags ...func()) configuration {
|
||||
@@ -19,12 +20,12 @@ func flags(prefix string, mountFlags ...func()) configuration {
|
||||
|
||||
flag.StringVar(&config.httpAddr, p("http-addr"), ":3000", "Listen address for HTTP server")
|
||||
flag.StringVar(&config.dbDSN, p("db-dsn"), "crust:crust@tcp(db1:3306)/crust?collation=utf8mb4_general_ci", "DSN for database connection")
|
||||
flag.IntVar(&config.monitorInterval, "monitor-interval", 300, "Monitor interval (seconds, 0 = disable)")
|
||||
|
||||
for _, mount := range mountFlags {
|
||||
mount()
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
return config
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ func main() {
|
||||
|
||||
// log to stdout not stderr
|
||||
log.SetOutput(os.Stdout)
|
||||
go NewMonitor(config.monitorInterval)
|
||||
|
||||
// set up database connection
|
||||
factory.Database.Add("default", config.dbDSN)
|
||||
|
||||
@@ -2,15 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/go-chi/chi/middleware"
|
||||
"github.com/go-chi/cors"
|
||||
"reflect"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// MountRoutes will register API routes
|
||||
func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes func(r chi.Router)) {
|
||||
func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes ...func(r chi.Router)) {
|
||||
// CORS for local development...
|
||||
cors := cors.New(cors.Options{
|
||||
AllowedOrigins: []string{"*"},
|
||||
@@ -25,7 +26,9 @@ func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes func(r chi.Router
|
||||
r.Use(middleware.Logger)
|
||||
}
|
||||
|
||||
mountRoutes(r)
|
||||
for _, mount := range mountRoutes {
|
||||
mount(r)
|
||||
}
|
||||
|
||||
var printRoutes func(chi.Routes, string, string)
|
||||
printRoutes = func(r chi.Routes, indent string, prefix string) {
|
||||
@@ -42,4 +45,6 @@ func MountRoutes(r chi.Router, opts *RouteOptions, mountRoutes func(r chi.Router
|
||||
}
|
||||
}
|
||||
printRoutes(r, "", "")
|
||||
|
||||
r.Mount("/debug", middleware.Profiler())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user