Documentation
¶
Overview ¶
Package bible is the core of alkitab-api: domain types, the Source and Corpus contracts, a caching Engine, and a fallback Chain for composing sources. Pair it with an adapter such as local (embedded/BYOD JSON) or scrape (runtime proxy) — dependencies always point inward.
Example ¶
The embedded public-domain sample works with zero configuration; point local.New at a data directory to serve full translations (BYOD).
package main
import (
"fmt"
"github.com/davidgrldo/alkitab-api/bible"
"github.com/davidgrldo/alkitab-api/local"
)
func main() {
src, err := local.New("")
if err != nil {
panic(err)
}
eng := bible.New(src)
ch, err := eng.Chapter("kjv", "3john", 1)
if err != nil {
panic(err)
}
for _, v := range ch.Verses {
if v.Number == 4 {
fmt.Println(v.Content)
}
}
}
Output: I have no greater joy than to hear that my children walk in truth.
Index ¶
- Variables
- func IndonesianBookName(id string) string
- func ResolveBookID(s string) (string, error)
- type Book
- type Chain
- type Chapter
- type Corpus
- type Engine
- func (e *Engine) Chapter(version, book string, chapter int) (*Chapter, error)
- func (e *Engine) DailyVerse(version string, t time.Time) (*VerseHit, error)
- func (e *Engine) RandomVerse(version string) (*VerseHit, error)
- func (e *Engine) Search(version, query string) ([]VerseHit, error)
- func (e *Engine) Source() Source
- type Source
- type Translation
- type Verse
- type VerseHit
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func IndonesianBookName ¶
IndonesianBookName returns the Indonesian name for a canonical id (used by the scrape adapter to build alkitab.mobi URLs). Empty string if unknown.
func ResolveBookID ¶
ResolveBookID resolves an id, English name/abbr, or Indonesian name/abbr (case-insensitive) to the canonical lowercase book id.
Types ¶
type Book ¶
type Book struct {
ID string `json:"id"`
Name string `json:"name"`
Abbreviation string `json:"abbr"`
Testament string `json:"testament"`
Chapters int `json:"chapters"`
}
func CanonicalBooks ¶
func CanonicalBooks() []Book
CanonicalBooks returns all 66 books as domain Book values (English names).
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain is a Source that delegates to members in order, returning the first non-ErrNotFound / non-ErrUnsupportedVersion result. Books returns the first non-error result; Translations are merged across members.
func (*Chain) AllVerses ¶
AllVerses delegates to the first member that implements Corpus, so that Search/Daily/Random keep working when local and scrape are chained.
func (*Chain) Translations ¶
func (c *Chain) Translations() []Translation
type Corpus ¶
Corpus is an optional capability for adapters with a fully loaded in-memory corpus. The Engine uses it to power Search, DailyVerse, and RandomVerse. Network-only adapters (scrape) do not implement it.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine wraps a Source with a chapter cache and corpus-backed operations.
func (*Engine) DailyVerse ¶
DailyVerse returns a deterministic verse for the given date and version: seed = fnv(date+version) % len(corpus). Same date+version always agrees.
func (*Engine) RandomVerse ¶
RandomVerse returns an unpredictable verse. Auto-seeded via math/rand/v2.
type Source ¶
type Source interface {
Translations() []Translation
Books(version string) ([]Book, error)
Chapter(version, book string, chapter int) (*Chapter, error)
}
Source is the mandatory contract every adapter implements.