bible

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 7 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound           = errors.New("bible: not found")
	ErrUnsupportedVersion = errors.New("bible: unsupported version")
	ErrUnsupportedFeature = errors.New("bible: feature not supported by active source")
)

Functions

func IndonesianBookName

func IndonesianBookName(id string) string

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

func ResolveBookID(s string) (string, error)

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 NewChain

func NewChain(sources ...Source) *Chain

func (*Chain) AllVerses

func (c *Chain) AllVerses(version string) ([]VerseHit, error)

AllVerses delegates to the first member that implements Corpus, so that Search/Daily/Random keep working when local and scrape are chained.

func (*Chain) Books

func (c *Chain) Books(version string) ([]Book, error)

func (*Chain) Chapter

func (c *Chain) Chapter(version, book string, chapter int) (*Chapter, error)

func (*Chain) Translations

func (c *Chain) Translations() []Translation

type Chapter

type Chapter struct {
	Translation string  `json:"version"`
	Book        string  `json:"book"`
	Number      int     `json:"chapter"`
	Verses      []Verse `json:"verses"`
}

type Corpus

type Corpus interface {
	AllVerses(version string) ([]VerseHit, error)
}

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 New

func New(src Source) *Engine

func (*Engine) Chapter

func (e *Engine) Chapter(version, book string, chapter int) (*Chapter, error)

func (*Engine) DailyVerse

func (e *Engine) DailyVerse(version string, t time.Time) (*VerseHit, error)

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

func (e *Engine) RandomVerse(version string) (*VerseHit, error)

RandomVerse returns an unpredictable verse. Auto-seeded via math/rand/v2.

func (*Engine) Search

func (e *Engine) Search(version, query string) ([]VerseHit, error)

Search returns verses whose content contains query (case-insensitive).

func (*Engine) Source

func (e *Engine) Source() Source

Source returns the underlying source (used by the server for listings).

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.

type Translation

type Translation struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	Language string `json:"language"`
}

type Verse

type Verse struct {
	Number  int    `json:"verse"`
	Content string `json:"content"`
	Type    string `json:"type"`
	Order   int    `json:"order"`
}

type VerseHit

type VerseHit struct {
	Translation string `json:"version"`
	Book        string `json:"book"`
	Chapter     int    `json:"chapter"`
	Verse       Verse  `json:"verse"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL