Added MustAsset function.

pull/4/head
Jens Breitbart 2015-03-08 12:42:30 +01:00
parent 8ee21af0fa
commit 81e20ed1b7
1 changed files with 11 additions and 0 deletions

11
toc.go
View File

@ -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.