snippets

package
v0.0.0-...-786626a Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultName = `Hello`

DefaultName is the name of the default snippet.

Variables

View Source
var DefaultCode string

DefaultCode is the default code that is shown in the playground when no other snippet is loaded.

Functions

func GetSnippet

func GetSnippet(name string) (string, bool)

GetSnippet returns the predefined snippet code for the given name. The name should not include the leading '#' character. If no predefined snippet exists for the given name, false is returned.

func SnippetNames

func SnippetNames() []string

SnippetNames returns the names of all predefined snippets. The names do not include the leading '#' character.

Types

type SnippetStore

type SnippetStore interface {
	// LocalOnly indicates the store instance only stores snippets locally.
	// This is for testing and protyping purposes only. It will use local
	// storage to store snippets instead of the remote snippet store.
	// Use this when on a fork to prevent CORS issues.
	LocalOnly() bool

	// SetLocalOnly will change if the snippet store is local or not.
	SetLocalOnly(localOnly bool)

	// Read fetches the code snippet with the given hash (including the `#/`)
	// from the snippet store.
	// If the has is `#` without the `/`, the remainder is checked to see
	// if it matches any pre-defined snippets, i.e. `#Hello`.
	// If the hash is empty or invalid, it returns the default code.
	//
	// This will not block but the then method will be called after
	// the network request has completed.
	Read(hash string, then func(string, error))

	// Write sends the given code snippet to the snippet store and returns
	// the snippet hash (including the `#/`) on success.
	//
	// This will not block but the then method will be called after
	// the network request has completed.
	Write(code string, then func(string, error))
}

SnippetStore represents a code snippet store for persisting and retrieving customer defined code snippets.

This interfaces allows the network access to be replaced with a mock implementation for testing.

func NewStore

func NewStore() SnippetStore

NewStore creates a new Store instance. This store will be initially set to read and write snippets to the remote snippet store.

Jump to

Keyboard shortcuts

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