Added Tpye instead map
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Andrea Cervesato 2020-12-08 12:46:52 +01:00
parent 13dc7b8945
commit aafdcf96ab
2 changed files with 18 additions and 12 deletions

28
main.go
View File

@ -15,10 +15,22 @@ import (
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
// Logic Jellyfin URL
type Logic struct { type Logic struct {
BaseURL string BaseURL string
} }
// PublicInfo Chromecast configuration Payload
type PublicInfo struct {
ID string
LocalAddress string
OperatingSystem string
ProductName string
ServerName string
StartupWizardCompleted bool
Version string
}
func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
logger := logginghandler.Logger(r) logger := logginghandler.Logger(r)
@ -50,24 +62,15 @@ func (l Logic) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
jd := map[string]string{} var jd PublicInfo
if err := json.Unmarshal(body, &jd); err != nil { if err := json.Unmarshal(body, &jd); err != nil {
logger.Error().Msg(err.Error()) logger.Error().Msg(err.Error())
http.Error(w, "could not unmarshal body", http.StatusInternalServerError) http.Error(w, "could not unmarshal body", http.StatusInternalServerError)
return return
} }
url := os.Getenv("JELLYFIN_URL")
// Delete LocalAddress from map. jd.LocalAddress = url
_, ok := jd["LocalAddress"]
if ok {
delete(jd, "LocalAddress")
} else {
logger.Debug().Msg("nothing to do")
return
}
nd, err := json.Marshal(jd) nd, err := json.Marshal(jd)
if err != nil { if err != nil {
logger.Error().Msg(err.Error()) logger.Error().Msg(err.Error())
@ -91,6 +94,7 @@ func main() {
l := Logic{BaseURL: os.Args[1]} l := Logic{BaseURL: os.Args[1]}
handler := logginghandler.Handler(l) handler := logginghandler.Handler(l)
http.Handle("/", handler) http.Handle("/", handler)
log.Info().Msg("starting server...") log.Info().Msg("starting server...")
log.Fatal().Msg(http.ListenAndServe("0.0.0.0:8088", nil).Error()) log.Fatal().Msg(http.ListenAndServe("0.0.0.0:8088", nil).Error())

View File

@ -1,5 +1,7 @@
module github.com/rs/zerolog module github.com/rs/zerolog
go 1.15
require ( require (
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1