func (sess *Session) GetWithType(key string, out interface{}) (err error) { value, ok := sess.data[key] if !ok { return fmt.Errorf("[GetWithType]key:%s not found", key) } return typeTransform.Transform(value, out) }
func MustOrmToRow(obj OrmObject) (row map[string]string) { row = map[string]string{} err := typeTransform.Transform(obj, &row) if err != nil { panic(err) } return row }
//读取json文件,并修正json的类型问题(map key 必须是string的问题) func ReadFileTypeFix(path string, obj interface{}) error { b, err := ioutil.ReadFile(path) if err != nil { return err } var iobj interface{} err = json.Unmarshal(b, &iobj) if err != nil { return err } return typeTransform.Transform(iobj, obj) }
/* Unmarshal excel into a array of a struct you must put data in first sheet accept []struct{Key1 value;Key2 value} or []map[string]string first excel row as struct key,remain excel row as struct value type can not convert will fail lack keys will be ignore */ func UnmarshalFile(filePath string, obj interface{}) (err error) { rawArray, err := XlsxFile2Array(filePath) if err != nil { return } gridArray, err := TitleArrayToGrid(rawArray[0]) if err != nil { return } err = typeTransform.Transform(gridArray, obj) if err != nil { return } return }
//Unmarshal excel into a array of a struct and skip some line from start func UnmarshalFileSkipLine(filePath string, obj interface{}, skipline int) (err error) { rawArray, err := XlsxFile2Array(filePath) if err != nil { return } if len(rawArray[0]) < skipline+1 { return fmt.Errorf("[kmgExcel.UnmarshalFileSkipLine]filePath:%s len(rawArray[0])<skipline+1 len(rawArray[0]):%d skipline:%d", filePath, len(rawArray[0]), skipline+1) } gridArray, err := TitleArrayToGrid(rawArray[0][skipline:]) if err != nil { return } err = typeTransform.Transform(gridArray, obj) if err != nil { return } return }
func OrmToRow(obj OrmObject) (row map[string]string, err error) { row = map[string]string{} err = typeTransform.Transform(obj, &row) return row, err }
func MustOrmFromRow(obj OrmObject, row map[string]string) { err := typeTransform.Transform(row, &obj) if err != nil { panic(err) } }
func OrmFromRow(obj OrmObject, row map[string]string) (OrmObject, error) { err := typeTransform.Transform(row, &obj) return obj, err }