knowyt/server/src/game/removeQuote.go

34 lines
546 B
Go

package game
import (
"fmt"
"os"
"sirlab.de/go/knyt/quote"
)
func (gm *Game) RemoveQuote(fileName, usrId, quoteId string) error {
if qu, err := gm.getQuoteById(quoteId); err != nil {
return err
} else {
if qu.GetSourceId() != usrId {
return fmt.Errorf("usrId does not match quote source id")
}
gm.removeQuoteFromList(qu)
}
err := os.Remove(fileName)
if err != nil {
return err
}
return nil
}
func (gm *Game) removeQuoteFromList(qu *quote.Quote) {
gm.mu.Lock()
defer gm.mu.Unlock()
delete(gm.quotes, qu.GetId())
}