diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 20:05:01 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 20:05:01 +0200 |
| commit | 5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06 (patch) | |
| tree | 5268e39568e6146521e4be9e0c1b70d3afca538c /wrms.go | |
| parent | ead811a4ebd0074cc4d42da53daacbb358229fac (diff) | |
| download | WRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.tar.gz WRMS-5ee0fb4aa53e02a4b6c2ffb3d5bfa3a6153c9a06.zip | |
implement YAML config and admin connections
Diffstat (limited to 'wrms.go')
| -rw-r--r-- | wrms.go | 36 |
1 files changed, 15 insertions, 21 deletions
@@ -2,7 +2,6 @@ package main import ( "encoding/json" - "strings" "muhq.space/go/wrms/llog" @@ -12,18 +11,18 @@ import ( ) type Song struct { - Title string `json:"title"` - Artist string `json:"artist"` - Source string `json:"source"` - Uri string `json:"uri"` - Weight int `json:"weight"` - index int `json:"-"` // used by heap.Interface - Upvotes map[string]struct{} `json:"-"` - Downvotes map[string]struct{} `json:"-"` + Title string `json:"title"` + Artist string `json:"artist"` + Source string `json:"source"` + Uri string `json:"uri"` + Weight int `json:"weight"` + index int `json:"-"` // used by heap.Interface + Upvotes map[uuid.UUID]struct{} `json:"-"` + Downvotes map[uuid.UUID]struct{} `json:"-"` } func NewSong(title, artist, source, uri string) Song { - return Song{title, artist, source, uri, 0, 0, map[string]struct{}{}, map[string]struct{}{}} + return Song{title, artist, source, uri, 0, 0, map[uuid.UUID]struct{}{}, map[uuid.UUID]struct{}{}} } func NewSongFromJson(data []byte) (Song, error) { @@ -34,8 +33,8 @@ func NewSongFromJson(data []byte) (Song, error) { return s, err } - s.Upvotes = map[string]struct{}{} - s.Downvotes = map[string]struct{}{} + s.Upvotes = map[uuid.UUID]struct{}{} + s.Downvotes = map[uuid.UUID]struct{}{} return s, nil } @@ -78,17 +77,12 @@ func NewWrms(config Config) *Wrms { wrms := Wrms{} wrms.Config = config wrms.Connections = make(map[uuid.UUID]*Connection) - wrms.Player = NewPlayer(&wrms, strings.Split(config.Backends, " ")) + wrms.Player = NewPlayer(&wrms, config.Backends) return &wrms } -func (wrms *Wrms) GetConn(connId string) *Connection { - id, err := uuid.Parse(connId) - if err != nil { - llog.Fatal("Failed to parse connId %s: %v", connId, err) - } - - return wrms.Connections[id] +func (wrms *Wrms) GetConn(connId uuid.UUID) *Connection { + return wrms.Connections[connId] } func (wrms *Wrms) Close() { @@ -158,7 +152,7 @@ func (wrms *Wrms) PlayPause() { wrms.Broadcast(ev) } -func (wrms *Wrms) AdjustSongWeight(connId string, songUri string, vote string) { +func (wrms *Wrms) AdjustSongWeight(connId uuid.UUID, songUri string, vote string) { for i := 0; i < len(wrms.Songs); i++ { s := &wrms.Songs[i] if s.Uri != songUri { |
