platform

package
v0.10.9 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CommitTypeFeat     = "feat"
	CommitTypeFix      = "fix"
	CommitTypeDocs     = "docs"
	CommitTypeStyle    = "style"
	CommitTypeRefactor = "refactor"
	CommitTypePerf     = "perf"
	CommitTypeTest     = "test"
	CommitTypeChore    = "chore"
)

CommitType constants for semantic commits

Variables

This section is empty.

Functions

func AppendFooter

func AppendFooter(msg string) string

AppendFooter appends the Loam footer to an arbitrary message if not present. Used for free-form -m "msg" commits.

func FindRoot added in v0.8.1

func FindRoot(startDir string) (string, error)

FindRoot recursively looks upwards for a vault root indicator. Indicators are: .loam directory, .git directory, or loam.json file. If found, returns the absolute path to the root. If not found (reached root of FS), returns the startDir (or error?). For now, if not found, we return an empty string to indicate "no specific root found".

func FormatChangeReason

func FormatChangeReason(ctype, scope, subject, body string) string

FormatChangeReason builds a Conventional Commit message (used as Change Reason). logic:

<type>(<scope>): <subject>

<body>

Powered-by: Loam

func Init

func Init(uri string, opts ...Option) (core.Repository, error)

Init initializes a new Loam vault based on the provided configuration. The 'uri' argument is adapter-specific (e.g., file path for 'fs', connection string for others).

It returns the configured core.Repository.

func IsDevRun

func IsDevRun() bool

IsDevRun checks if the current process is running via `go run` or `go test`. It relies on the fact that these commands build binaries in temporary directories.

func New

func New(uri string, opts ...Option) (*core.Service, error)

svc, err := loam.New("./path/to/vault", loam.WithVersioning(false)) The URI argument is adapter-specific (e.g., file path for 'fs', connection string for others).

func ResolveVaultPath

func ResolveVaultPath(userPath string, forceTemp bool) string

ResolveVaultPath determines the actual path for the vault based on safety rules. If isDev is true (or forced), it re-roots the path into a temporary directory to avoid polluting the user's workspace/host repo.

func Sync

func Sync(uri string, opts ...Option) error

Sync synchronizes the vault at the given URI with its remote.

Types

type Option

type Option func(*options)

Option defines a functional option for configuring Loam.

func WithAdapter

func WithAdapter(name string) Option

WithAdapter allows specifying the storage adapter to use by name (e.g. "fs"). Defaults to "fs".

func WithAutoInit

func WithAutoInit(auto bool) Option

WithAutoInit enables automatic initialization of the vault (creates directory and git init).

func WithContentExtraction added in v0.10.8

func WithContentExtraction(enabled bool) Option

WithContentExtraction controls whether JSON/YAML/CSV content fields are extracted into Document.Content. When disabled, the file payload is preserved 1:1 in Metadata.

func WithDevSafety added in v0.10.6

func WithDevSafety(enabled bool) Option

WithDevSafety controls the "Sandbox" safety mechanism when running via `go run`. By default (true), Loam forces a temporary directory to prevent accidental data loss. Setting this to false allows operating on the real filesystem even during `go run`.

CAUTION: Only disable this if you are sure your code is safe.

func WithEventBuffer added in v0.9.0

func WithEventBuffer(size int) Option

WithEventBuffer allows specifying the size of the event broker buffer. Zero means default (100).

func WithForceTemp

func WithForceTemp(force bool) Option

WithForceTemp forces the use of a temporary directory (useful for testing).

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets the logger for the service.

func WithMarkdownBodyKey added in v0.10.8

func WithMarkdownBodyKey(key string) Option

WithMarkdownBodyKey sets the metadata key used to store Markdown body when content extraction is disabled. Defaults to "body".

func WithMustExist

func WithMustExist(must bool) Option

WithMustExist ensures the vault directory must already exist.

func WithReadOnly added in v0.10.6

func WithReadOnly(enabled bool) Option

WithReadOnly enables read-only mode. In this mode: 1. Write operations (Save, Delete, Sync) return ErrReadOnly. 2. Initialization (Mkdir, Git Init) is skipped. 3. Cache updates are not persisted to disk. 4. Dev Safety Lock (go run temp dir) is BYPASSED (uses real path).

func WithRepository

func WithRepository(repo core.Repository) Option

WithRepository allows injecting a custom storage adapter (e.g. mock, s3). If provided, the default filesystem adapter will be skipped.

func WithSerializer added in v0.10.2

func WithSerializer(ext string, s any) Option

WithSerializer registers a custom serializer for a specific extension. The serializer 's' must implement the adapter's Serializer interface (e.g. fs.Serializer). Using 'any' keeps the public API clean, but validation happens at runtime during Init.

func WithStrict added in v0.10.4

func WithStrict(strict bool) Option

WithStrict enables strict mode for all default serializers. When enabled, numbers in JSON/YAML/Markdown will be parsed as json.Number (string based) to preserve precision of large integers.

func WithSystemDir added in v0.6.0

func WithSystemDir(name string) Option

WithSystemDir allows specifying the hidden directory name (e.g. ".loam"). Defaults to ".loam" if not set (handled by adapter).

func WithVersioning

func WithVersioning(enabled bool) Option

WithVersioning enables or disables version control (e.g. Git). By default, versioning is enabled. Passing false will disable versioning (no-versioning mode).

func WithWatcherErrorHandler added in v0.10.5

func WithWatcherErrorHandler(fn func(error)) Option

WithWatcherErrorHandler registers a callback to handle errors occurring during the Watch loop. This allows applications to log or react to runtime watcher failures (e.g. permission denied) which are otherwise only logged.

Jump to

Keyboard shortcuts

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