func init() { // gob encoding/decoding: register types for sessions and flashes. gob.Register(SessionData{}) gob.Register([]interface{}{}) // Register the default session store. DefaultSessionFactory.SetStore("cookie", new(CookieSessionStore)) }
func compile(empty interface{}) (comp eventFactory) { gob.Register(empty) val := reflect.ValueOf(empty) if val.Kind() != reflect.Ptr || val.Elem().Kind() != reflect.Struct { panic("combatlog: compile: cannot compile a non-pointer-to-struct value") } comp.emptyPtr = val.Interface() val = val.Elem() comp.emptyTyp = val.Type() optional := false var next func([]int, reflect.Value) next = func(curr []int, val reflect.Value) { typ := val.Type() for i, n := 0, val.NumField(); i < n; i++ { // Get the recursive index idx := make([]int, len(curr)+1) idx[copy(idx, curr)] = i fval := val.Field(i) ftyp := typ.Field(i) if ftyp.Tag.Get("combatlog") == "optional" { optional = true } var curField field switch ftyp.Type.Kind() { case reflect.Struct: next(idx, fval) case reflect.Int32: curField = fieldInt32{fval.Addr().Interface().(*int32)} case reflect.Int64: curField = fieldInt64{fval.Addr().Interface().(*int64)} case reflect.Uint32: curField = fieldUint32{fval.Addr().Interface().(*uint32)} case reflect.Uint64: curField = fieldUint64{fval.Addr().Interface().(*uint64)} case reflect.Bool: curField = fieldBool{fval.Addr().Interface().(*bool)} case reflect.String: curField = fieldString{fval.Addr().Interface().(*string)} default: panic("cannot compile field of type " + ftyp.Type.Kind().String()) } if curField != nil { if !optional { comp.min++ } comp.max++ comp.fields = append(comp.fields, curField) } } } next(nil, val) return comp }
func RegisterTypes() { gob.Register(make(PlaceVector, 0)) gob.Register(make(PersonVector, 0)) gob.Register( LunchPoll{ Places: make(PlaceVector, 0), Votes: make(map[string]*Place), IndexCounter: 1}) gob.Register( Place{ Id: 0, Name: "No Where", Votes: 0, People: make(PersonVector, 0), Nominator: &Person{ CanDrive: false, Name: "", NominationsLeft: 2}}) gob.Register( Person{ CanDrive: false, Name: "", NominationsLeft: 2}) }
func init() { // Allow remotization (gob-ability) of my own error... gob.Register(new(myError)) }
func init() { gob.Register(ActiveAct{}) }