Last active
July 26, 2019 14:27
-
-
Save kasvith/d85df583c89231dada777a6d48ea2d56 to your computer and use it in GitHub Desktop.
defaults.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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