fix: export JSON fields from type
This commit is contained in:
parent
4aa016325f
commit
975658f449
2 changed files with 18 additions and 18 deletions
34
main.go
34
main.go
|
@ -10,10 +10,10 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
type telemetry struct {
|
||||
slug string `json:"slug"`
|
||||
eventType string `json:"type"`
|
||||
qualityChangeUp bool `json:"isUp"`
|
||||
type Telemetry struct {
|
||||
Slug string `json:"slug"`
|
||||
EventType string `json:"type"`
|
||||
QualityChangeUp bool `json:"isUp"`
|
||||
}
|
||||
|
||||
type metrics struct {
|
||||
|
@ -24,9 +24,9 @@ type metrics struct {
|
|||
}
|
||||
|
||||
const (
|
||||
type_buffering = "buffering"
|
||||
type_recovery = "recovery"
|
||||
type_quality_switch = "quality_switch"
|
||||
typeBuffering = "buffering"
|
||||
typeRecovery = "recovery"
|
||||
typeQualitySwitch = "quality_switch"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -60,22 +60,22 @@ func main() {
|
|||
|
||||
func telemetryHandler(m metrics) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
t := new([]telemetry)
|
||||
t := new([]Telemetry)
|
||||
if err := c.Bind(t); err != nil {
|
||||
return c.String(http.StatusBadRequest, "bad request")
|
||||
}
|
||||
|
||||
for _, v := range *t {
|
||||
switch v.eventType {
|
||||
case type_buffering:
|
||||
m.buffering.WithLabelValues(v.slug).Inc()
|
||||
case type_recovery:
|
||||
m.recovery.WithLabelValues(v.slug).Inc()
|
||||
case type_quality_switch:
|
||||
if v.qualityChangeUp {
|
||||
m.qualityUp.WithLabelValues(v.slug).Inc()
|
||||
switch v.EventType {
|
||||
case typeBuffering:
|
||||
m.buffering.WithLabelValues(v.Slug).Inc()
|
||||
case typeRecovery:
|
||||
m.recovery.WithLabelValues(v.Slug).Inc()
|
||||
case typeQualitySwitch:
|
||||
if v.QualityChangeUp {
|
||||
m.qualityUp.WithLabelValues(v.Slug).Inc()
|
||||
} else {
|
||||
m.qualityDown.WithLabelValues(v.slug).Inc()
|
||||
m.qualityDown.WithLabelValues(v.Slug).Inc()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ let
|
|||
deps = [ ];
|
||||
nativeDeps = [ ];
|
||||
in
|
||||
pkgs.buildGo119Module {
|
||||
pkgs.buildGo121Module {
|
||||
pname = "voc-telemetry";
|
||||
inherit version;
|
||||
src = ./.;
|
||||
|
|
Loading…
Reference in a new issue