feat: middleware, expvar
This commit is contained in:
@@ -3,8 +3,10 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"expvar"
|
||||
"flag"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -34,7 +36,8 @@ type config struct {
|
||||
maxOpenConns int
|
||||
maxIdleConns int
|
||||
maxIdleTime string
|
||||
} // Add a new limiter struct containing fields for the requests-per-second and burst
|
||||
}
|
||||
// Add a new limiter struct containing fields for the requests-per-second and burst
|
||||
// values, and a boolean field which we can use to enable/disable rate limiting
|
||||
// altogether.
|
||||
limiter struct {
|
||||
@@ -138,6 +141,23 @@ func main() {
|
||||
// established.
|
||||
logger.PrintInfo("database connection pool established", nil)
|
||||
|
||||
// Publish a new "version" variable in the expvar handler containing our application
|
||||
// version number (currently the constant "1.0.0").
|
||||
expvar.NewString("version").Set(version)
|
||||
expvar.Publish("goroutines", expvar.Func(func() any {
|
||||
return runtime.NumGoroutine()
|
||||
}))
|
||||
|
||||
// Publish the database connection pool statistics.
|
||||
expvar.Publish("database", expvar.Func(func() any {
|
||||
return db.Stats()
|
||||
}))
|
||||
|
||||
// Publish the current Unix timestamp.
|
||||
expvar.Publish("timestamp", expvar.Func(func() any {
|
||||
return time.Now().Unix()
|
||||
}))
|
||||
|
||||
app := &application{
|
||||
config: cfg,
|
||||
logger: logger,
|
||||
|
||||
Reference in New Issue
Block a user