Is it possible to go in go type structure as a parameter of a function / method? For example:
type MyEntity struct {} type MyEntity2 struct {} func goProc(t type) { b := make(t) } func TestEncription(test *testing.T) { goProc(MyEntity.type) goProc(MyEntity2.type) } Pishu banding from db. If one entry is ok:
type DbEntity interface { bindEntity(rows *pgx.Rows, descriptionSlice []pgx.FieldDescription, colsCount *int) }
func (customerEntity *CustomerEntity) bindEntity(rows *pgx.Rows, descriptionSlice []pgx.FieldDescription, colsCount *int) { val, _ := rows.Values() for i := 0; i < *colsCount; i++ { switch descriptionSlice[i].Name { case "customer_id": customerEntity.CustomerId = val[i].(int64) case "account_name": customerEntity.AccountName = val[i].(string) case "customer_name": customerEntity.CustomerName = val[i].(string) } } }
But if the sheet (slice) objects the problem
func queryForList(rows *pgx.Rows) []interface{} { defer rows.Close() descriptionSlice := rows.FieldDescriptions() colsCount := len(descriptionSlice) var entitySlice []interface{} for rows.Next() { //entity := CustomerEntity{} //entitySlice = append(entitySlice, bindEntityFunc(rows, descriptionSlice, &colsCount)) } return entitySlice }
queryForList - for all types of entities. And he doesn’t know anything about types