fix: export JSON fields from type

This commit is contained in:
Garionion 2023-12-29 11:13:57 +01:00
parent 4aa016325f
commit 975658f449
No known key found for this signature in database
2 changed files with 18 additions and 18 deletions

34
main.go
View file

@ -10,10 +10,10 @@ import (
"net/http" "net/http"
) )
type telemetry struct { type Telemetry struct {
slug string `json:"slug"` Slug string `json:"slug"`
eventType string `json:"type"` EventType string `json:"type"`
qualityChangeUp bool `json:"isUp"` QualityChangeUp bool `json:"isUp"`
} }
type metrics struct { type metrics struct {
@ -24,9 +24,9 @@ type metrics struct {
} }
const ( const (
type_buffering = "buffering" typeBuffering = "buffering"
type_recovery = "recovery" typeRecovery = "recovery"
type_quality_switch = "quality_switch" typeQualitySwitch = "quality_switch"
) )
func main() { func main() {
@ -60,22 +60,22 @@ func main() {
func telemetryHandler(m metrics) echo.HandlerFunc { func telemetryHandler(m metrics) echo.HandlerFunc {
return func(c echo.Context) error { return func(c echo.Context) error {
t := new([]telemetry) t := new([]Telemetry)
if err := c.Bind(t); err != nil { if err := c.Bind(t); err != nil {
return c.String(http.StatusBadRequest, "bad request") return c.String(http.StatusBadRequest, "bad request")
} }
for _, v := range *t { for _, v := range *t {
switch v.eventType { switch v.EventType {
case type_buffering: case typeBuffering:
m.buffering.WithLabelValues(v.slug).Inc() m.buffering.WithLabelValues(v.Slug).Inc()
case type_recovery: case typeRecovery:
m.recovery.WithLabelValues(v.slug).Inc() m.recovery.WithLabelValues(v.Slug).Inc()
case type_quality_switch: case typeQualitySwitch:
if v.qualityChangeUp { if v.QualityChangeUp {
m.qualityUp.WithLabelValues(v.slug).Inc() m.qualityUp.WithLabelValues(v.Slug).Inc()
} else { } else {
m.qualityDown.WithLabelValues(v.slug).Inc() m.qualityDown.WithLabelValues(v.Slug).Inc()
} }
} }
} }

View file

@ -5,7 +5,7 @@ let
deps = [ ]; deps = [ ];
nativeDeps = [ ]; nativeDeps = [ ];
in in
pkgs.buildGo119Module { pkgs.buildGo121Module {
pname = "voc-telemetry"; pname = "voc-telemetry";
inherit version; inherit version;
src = ./.; src = ./.;