// Register adds the values to the models registry
Register adds the values to the models registry
// Register adds the values to the models registry
func (m *Model) Register(values ...interface{}) error {
	models := make(map[string]reflect.Value)
	if len(values) > 0 {
		for _, val := range values {
			rVal := reflect.ValueOf(val)
			if rVal.Kind() == reflect.Ptr {
				rVal = rVal.Elem()
			}
			switch rVal.Kind() {
			case reflect.Struct:
				models[getTypName(rVal.Type())] = reflect.New(rVal.Type())
			default:
				return errors.New("models: models must be structs")
			}
		}
	}
	for k, v := range models {
		m.models[k] = v
	}
	return nil
}
func ( m * Model ) Register ( values ... interface { } ) error { models := make ( map [ string ] reflect . Value ) if len ( values ) > 0 { for _ , val := range values { rVal := reflect . ValueOf ( val ) if rVal . Kind ( ) == reflect . Ptr { rVal = rVal . Elem ( ) } switch rVal . Kind ( ) { case reflect . Struct : models [ getTypName ( rVal . Type ( ) ) ] = reflect . New ( rVal . Type ( ) ) default : return errors . New ( " " ) } } } for k , v := range models { m . models [ k ] = v } return nil }
Register adds the values to the models registry
Register adds the values to the models registry
// do not work on them.models first, this is like an insurance policy // whenever we encounter any error in the values nothing goes into the registry