mirror of
https://github.com/woodchen-ink/random-api-go.git
synced 2025-07-18 13:52:02 +08:00
- Updated docker-compose.yml to mount logs directory. - Changed BASE_URL environment variable to point to the new API endpoint. - Refactored main.go to implement a structured App type, improving initialization and graceful shutdown. - Enhanced config management with JSON loading and environment variable support. - Added monitoring capabilities in api_handler for logging request metrics. - Introduced new metrics display in index.html with corresponding CSS styles for better visualization.
40 lines
909 B
Go
40 lines
909 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"random-api-go/router"
|
|
"random-api-go/stats"
|
|
)
|
|
|
|
type Router interface {
|
|
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
}
|
|
|
|
type Handlers struct {
|
|
Stats *stats.StatsManager
|
|
}
|
|
|
|
func (h *Handlers) HandleAPIRequest(w http.ResponseWriter, r *http.Request) {
|
|
HandleAPIRequest(w, r)
|
|
}
|
|
|
|
func (h *Handlers) HandleStats(w http.ResponseWriter, r *http.Request) {
|
|
HandleStats(w, r)
|
|
}
|
|
|
|
func (h *Handlers) HandleURLStats(w http.ResponseWriter, r *http.Request) {
|
|
HandleURLStats(w, r)
|
|
}
|
|
|
|
func (h *Handlers) HandleMetrics(w http.ResponseWriter, r *http.Request) {
|
|
HandleMetrics(w, r)
|
|
}
|
|
|
|
func (h *Handlers) Setup(r *router.Router) {
|
|
r.HandleFunc("/pic/", h.HandleAPIRequest)
|
|
r.HandleFunc("/video/", h.HandleAPIRequest)
|
|
r.HandleFunc("/stats", h.HandleStats)
|
|
r.HandleFunc("/urlstats", h.HandleURLStats)
|
|
r.HandleFunc("/metrics", h.HandleMetrics)
|
|
}
|