Added MustAsset function.
This commit is contained in:
parent
8ee21af0fa
commit
81e20ed1b7
11
toc.go
11
toc.go
|
@ -170,6 +170,17 @@ func Asset(name string) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("Asset %%s not found", name)
|
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.
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
// It returns an error if the asset could not be found or
|
// It returns an error if the asset could not be found or
|
||||||
// could not be loaded.
|
// could not be loaded.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user