Skip to content

Instantly share code, notes, and snippets.

@kasvith
Last active July 26, 2019 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasvith/d85df583c89231dada777a6d48ea2d56 to your computer and use it in GitHub Desktop.
Save kasvith/d85df583c89231dada777a6d48ea2d56 to your computer and use it in GitHub Desktop.
defaults.go
//go:generate go run gen.go
package box
type resourceBox struct {
storage map[string][]byte
}
func newResourceBox() *resourceBox {
return &resourceBox{storage: make(map[string][]byte)}
}
// Find a file
func (r *resourceBox) Has(file string) bool {
if _, ok := r.storage[file]; ok {
return true
}
return false
}
// Get file's content
func (r *resourceBox) Get(file string) ([]byte, bool) {
if f, ok := r.storage[file]; ok {
return f, ok
}
return nil, false
}
// Add a file to box
func (r *resourceBox) Add(file string, content []byte) {
r.storage[file] = content
}
// Resource expose
var resources = newResourceBox()
// Get a file from box
func Get(file string) ([]byte, bool) {
return resources.Get(file)
}
// Add a file content to box
func Add(file string, content []byte) {
resources.Add(file, content)
}
// Has a file in box
func Has(file string) bool {
return resources.Has(file)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment