Create some subroutines and test

This commit is contained in:
Bel LaPointe
2021-03-14 23:29:50 -05:00
parent 60adca804b
commit d79721b760
8 changed files with 578 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
package operation
import (
"encoding/json"
"errors"
"local/sandbox/cards/src/entity"
)
type Bool func(*entity.Game, interface{}) bool
var boolStringified = map[string]Bool{
"charge": charge,
"deal": deal,
"bet": bet,
"trade": trade,
"end": end,
}
func (foo *Bool) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
return foo.FromString(s)
}
func (foo *Bool) FromString(s string) error {
for k, v := range boolStringified {
if k == s {
*foo = v
return nil
}
}
return errors.New("unknown bool method " + s)
}