You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.0 KiB
Go

package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/noahlann/nnet/pkg/nnet"
)
// This example demonstrates enabling metrics and health checks.
// Start the server, then visit the metrics endpoint (if port configured) or use the built-in path.
func main() {
cfg := &nnet.Config{
Addr: "tcp://:8082",
Metrics: &nnet.MetricsConfig{
Enabled: true,
Path: "/metrics",
Port: 0, // same process
},
Session: &nnet.SessionConfig{
Storage: "memory",
Expiration: 1 * time.Hour,
},
}
srv, err := nnet.NewServer(cfg)
if err != nil {
log.Fatal("create server:", err)
}
// Simple route for probing
srv.Router().RegisterString("/health", func(ctx nnet.Context) error {
return ctx.Response().WriteString("ok")
})
log.Println("metrics_health listening on :8082; metrics enabled at /metrics")
if err := srv.Start(); err != nil {
log.Fatal("start server:", err)
}
defer srv.Stop()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
}