Manages application statistics retrieval using database-driven JSON queries. Reuse when implementing dashboard metrics or system telemetry endpoints.
// Source: https://github.com/artifacthub/hub | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
package stats
import (
"context"
"github.com/artifacthub/hub/internal/hub"
"github.com/artifacthub/hub/internal/util"
)
const (
// Database queries
getStatsDBQ = `select get_stats()`
)
// Manager provides an API to manage stats.
type Manager struct {
db hub.DB
}
// NewManager creates a new Manager instance.
func NewManager(db hub.DB) *Manager {
return &Manager{
db: db,
}
}
// GetJSON returns some stats as a json object built by the database.
func (m *Manager) GetJSON(ctx context.Context) ([]byte, error) {
return util.DBQueryJSON(ctx, m.db, getStatsDBQ)
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key