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 ¶
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 ¶
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 ¶
ExampleByName is the sample called name, with its text.