knowyt/server/src/game/getQuote.go

30 lines
508 B
Go
Raw Normal View History

2021-09-06 21:31:09 +00:00
package game
import (
"fmt"
"sirlab.de/go/knowyt/quote"
2021-09-06 21:31:09 +00:00
)
func (gm *Game) getQuoteById(id string) (*quote.Quote, error) {
gm.mu.Lock()
defer gm.mu.Unlock()
quote := gm.quotes[id]
if quote == nil {
2021-10-15 21:07:41 +00:00
return nil, fmt.Errorf("quote id \"%s\" not found in game\n", id)
2021-09-06 21:31:09 +00:00
}
return quote, nil
}
2021-09-11 12:03:44 +00:00
func (gm *Game) getAllQuotes() []*quote.Quote {
gm.mu.Lock()
defer gm.mu.Unlock()
quotes := make([]*quote.Quote, 0)
for _, quote := range gm.quotes {
quotes = append(quotes, quote)
}
return quotes
}