Gregory Eremin f9382cc766 | ||
---|---|---|
LICENCE | ||
README.md | ||
caller.go | ||
caller_test.go |
README.md
Caller
Package caller is used to dynamically call functions with data unmarshalled into the functions' first argument. Its main purpose is to hide common unmarshalling code from each function implementation thus reducing boilerplate and making package interaction code sexier.
Caller abstracts away the process of unmarshaling data before processing.
type PriceUpdate struct {
Product string `json:"product"`
Amount float32 `json:"amount"`
}
func PriceUpdatePrinter(p PriceUpdate) {
log.Printf("Price for %q is now $%.2f", p.Product, p.Amount)
}
// Error handling is skipped for clarity
func main() {
printer, _ := caller.New(PriceUpdatePrinter)
_ = printer.Call([]byte(`{"product": "Paperclip", "amount": 0.01}`))
}