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

View File

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