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

scripts

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package scripts carries dbc's sample scripts and new-script templates inside the binary, so a fresh install has working examples without a checkout, and they never go stale against the sdb API of the binary that ships them.

The files beside this one are the samples (named in the embed directive below). Each carries //go:build ignore and is package main, so `go build ./...` never meets them and this package (scripts) never mixes with theirs. The templates are in templates/, built the same way.

scripts/
    embed.go            ◄─ this package
    copy_table.go       ◄─ an Example: read-only, Duplicate copies it out
    loop_params.go
    …
    templates/
        blank.go        ◄─ a Template: what New starts from
        copy.go
        …

Examples are listed after the user's own scripts and never written to (the scripts store, userdata/scripts.go, only touches scripts_dir). A template is filled with connection names on the way out (Fill): it says "{{conn}}" and "{{conn2}}" inside string literals, so the template file stays valid Go that Check passes as it is.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fill

func Fill(name string, conns []string) (string, bool)

Fill is template name's text with connection names put in: "{{conn}}" becomes the first of conns and "{{conn2}}" the second (the copy template's source and destination). Each is written as a Go string literal (strconv.Quote), so a name with a quote or backslash in it still makes a script that compiles. Missing names become placeholders.

func IsExample

func IsExample(src []byte) bool

IsExample reports whether src is, byte for byte apart from line endings, one of the built-in samples: a copy that holds nothing the binary does not already carry. config's warning about the old ./scripts directory uses it, so a dbc checkout (whose ./scripts is these very samples) is not told to move them.

Types

type Example

type Example struct {
	Name string `json:"name"` // file name, with .go
	Desc string `json:"desc"` // as userdata.DescOf reads it, less the "Sample dbc script: " lead
	Text string `json:"-"`    // the source; large, so not in a listing
}

Example is one built-in sample script.

func ExampleByName

func ExampleByName(name string) (Example, bool)

ExampleByName is the sample called name, with its text.

func Examples

func Examples() []Example

Examples lists the built-in samples by name.

type Template

type Template struct {
	Name  string `json:"name"`  // its key, e.g. "copy"
	Title string `json:"title"` // a few words, for a menu
	Desc  string `json:"desc"`  // its description line: what the new script will say it does
}

Template is one starting point for a new script.

func Templates

func Templates() []Template

Templates lists the templates in menu order, each with its description.

Jump to

Keyboard shortcuts

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