Documentation
¶
Index ¶
Constants ¶
const DefaultName = `Hello`
DefaultName is the name of the default snippet.
Variables ¶
var DefaultCode string
DefaultCode is the default code that is shown in the playground when no other snippet is loaded.
Functions ¶
func GetSnippet ¶
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.