package quote import ( "encoding/json" "fmt" "os" "path" "strings" ) func NewQuoteFromFile(fileName string) (*Quote, error) { jsonBytes, err := os.ReadFile(fileName) if err != nil { return nil, err } var quJson QuoteJson if err := json.Unmarshal(jsonBytes, &quJson); err != nil { return nil, fmt.Errorf("%s: %v\n", fileName, err) } else { _, fileNameShort := path.Split(fileName) id := strings.TrimSuffix(fileNameShort, ".json") qu := &Quote{ id: id, sourceId: quJson.SourceId, quote: quJson.Quote, isPlayed: false, } return qu, nil } } func (qu *Quote) GetId() string { return qu.id } func (qu *Quote) GetSourceId() string { return qu.sourceId } func (qu *Quote) GetQuote() string { return qu.quote } func (qu *Quote) IsPlayed() bool { return qu.isPlayed } func (qu *Quote) SetIsPlayed() { qu.isPlayed = true }