61 lines
952 B
Go
61 lines
952 B
Go
package bible
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type Bible struct {
|
|
}
|
|
|
|
type Metadata struct {
|
|
}
|
|
|
|
type Book struct {
|
|
}
|
|
|
|
type Chapter struct {
|
|
}
|
|
|
|
type VerseSpec struct {
|
|
}
|
|
|
|
type Scripture struct {
|
|
Verse string `json:"verse"`
|
|
Translation string `json:"translation"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
type ScriptureStore struct {
|
|
Verses []*Scripture `json:"verses"`
|
|
Offset int `json:"offset"`
|
|
}
|
|
|
|
func (s *ScriptureStore) GetVerse() *Scripture {
|
|
defer func() {
|
|
if s.Offset+1 < len(s.Verses) {
|
|
s.Offset++
|
|
} else {
|
|
s.Offset = 0
|
|
}
|
|
}()
|
|
return s.Verses[s.Offset]
|
|
}
|
|
|
|
func OpenStore(name string) (*ScriptureStore, error) {
|
|
s := &ScriptureStore{}
|
|
buf, err := os.ReadFile(name)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
err = json.Unmarshal(buf, s)
|
|
return s, err
|
|
}
|
|
|
|
func SaveStore(name string, s *ScriptureStore) error {
|
|
buf, err := json.Marshal(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return os.WriteFile(name, buf, 0o644)
|
|
}
|