Help us shape the future of Go! Take the 2026 Go Developer Survey

templates

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package templates holds the starting structures a new project can be created from: a directory skeleton plus the AGENTS.md that explains it.

The files are go:embed'ed rather than fetched, because `cmd/bdrive` is one binary serving the CLI, the daemon and the hub — so the hub that seeds a project at creation and the client that seeds one with `bdrive init --template` read the identical set, with no gallery and no drift.

The AGENTS.md is the deliverable. Directories are the easy half and the half that decays; what makes a structure stick is the instruction file telling an agent where a new note goes, when something is archived, and what a good filename looks like.

One hard rule for the content: BearDrive syncs paths, not directories (internal/syncer/walk.go only journals regular files), so an empty directory never reaches a teammate. Every directory in a template holds at least one real file — asserted in the tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names lists the valid template names, for error messages.

func SafePath added in v0.15.0

func SafePath(p string) bool

SafePath reports whether p is a path a template may name: a clean, relative, control-character-free path inside the project. It is the one rule both seeding doors apply — WriteTo on disk, and the hub's seedTemplate, which hands it to cleanUploadPath as well.

The rule is journal.SafePath: a template file becomes an Op.Path on every device, so this door may not be more permissive than the journal is.

Types

type File

type File struct {
	Path    string `json:"path"`
	Content string `json:"-"`
}

File is one file of a template: a slash-separated path relative to the project root, and its literal content.

type Template

type Template struct {
	Name  string `json:"name"`  // the flag/API value, e.g. "docs"
	Title string `json:"title"` // what a menu shows, e.g. "Docs + decision records"
	Blurb string `json:"blurb"` // the one-line shape, e.g. "docs/, decisions/"
	Files []File `json:"-"`
}

Template is one starting structure.

func Get

func Get(name string) (Template, error)

Get returns the named template. An unknown name errors, naming the set.

func List

func List() []Template

List returns every shipped template, recommended first.

func (Template) Dirs

func (t Template) Dirs() []string

Dirs lists every directory a template's paths imply, for the every-directory-holds-a-file check.

func (Template) WriteTo

func (t Template) WriteTo(dir string) ([]string, error)

WriteTo writes the template into dir and returns the paths it wrote. A path that already exists is never overwritten and is left out of the result — which is what makes seeding twice a no-op rather than a divergence. Template and File are exported with exported fields, so "today every template comes from the go:embed" is a property of the callers, not of this function: the guard belongs where the write happens.

Jump to

Keyboard shortcuts

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