Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support []interface{} as json package does #267

Open
CaledoniaProject opened this issue Dec 2, 2023 · 0 comments
Open

Support []interface{} as json package does #267

CaledoniaProject opened this issue Dec 2, 2023 · 0 comments

Comments

@CaledoniaProject
Copy link

CaledoniaProject commented Dec 2, 2023

Hi there,

I'm wondering why encoding/json could work with []interface{} but not gocsv, can you explain why won't you implement that?

I had to do a lot a reflect job to fix this, it looks very much unnecessary to me, e.g

func DoEncode(tx *gorm.DB, resultModel interface{}, query string) {
  var (
    result = reflect.New(resultType).Interface()
  )

  // use gorm to fill result repeatly
  ...
  tx.ScanRows(rows, result)
  ...

  resultSlice := reflect.MakeSlice(reflect.SliceOf(resultType), 1, 1)
  resultSlice = reflect.Append(resultSlice, reflect.ValueOf(result).Elem())

  data, err := gocsv.MarshalString(resultSlice.Interface())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant