diff --git a/toc.go b/toc.go index 0228410..e3c9f91 100644 --- a/toc.go +++ b/toc.go @@ -170,6 +170,17 @@ func Asset(name string) ([]byte, error) { return nil, fmt.Errorf("Asset %%s not found", name) } +// MustAsset is like Asset but panics when Asset would return an error. +// It simplifies safe initialization of global variables. +func MustAsset(name string) []byte { + a, err := Asset(name) + if (err != nil) { + panic("asset: Asset(" + name + "): " + err.Error()) + } + + return a +} + // AssetInfo loads and returns the asset info for the given name. // It returns an error if the asset could not be found or // could not be loaded.