// It's possible that this method will generate duplicate JSON tag values
//
//   Columns: count, count,   count_2
//    Fields: Count, Count_2, Count2
// JSON tags: count, count_2, count_2
//
// This is unlikely to happen, so don't fix it yet
It's possible that this method will generate duplicate JSON tag values



This is unlikely to happen, so don't fix it yet
// It ' s possible that this method will generate duplicate JSON tag values // // Columns : count count count_2 // Fields : Count Count_2 Count2 // JSON tags : count count_2 count_2 // // This is unlikely to happen so don ' t fix it yet
func columnsToStruct(r *compiler.Result, name string, columns []goColumn, settings config.CombinedSettings) *Struct {
	gs := Struct{
		Name: name,
	}
	seen := map[string]int{}
	suffixes := map[int]int{}
	for i, c := range columns {
		colName := columnName(c.Column, i)
		tagName := colName
		fieldName := StructName(colName, settings)
		suffix := 0
		if o, ok := suffixes[c.id]; ok {
			suffix = o
		} else if v := seen[colName]; v > 0 {
			suffix = v + 1
		}
		suffixes[c.id] = suffix
		if suffix > 0 {
			tagName = fmt.Sprintf("%s_%d", tagName, suffix)
			fieldName = fmt.Sprintf("%s_%d", fieldName, suffix)
		}
		tags := map[string]string{}
		if settings.Go.EmitDBTags {
			tags["db:"] = tagName
		}
		if settings.Go.EmitJSONTags {
			tags["json:"] = tagName
		}
		gs.Fields = append(gs.Fields, Field{
			Name: fieldName,
			Type: goType(r, c.Column, settings),
			Tags: tags,
		})
		seen[colName]++
	}
	return &gs
}
func columnsToStruct ( r * compiler . Result , name string , columns [ ] goColumn , settings config . CombinedSettings ) * Struct { gs := Struct { Name : name , } seen := map [ string ] int { } suffixes := map [ int ] int { } for i , c := range columns { colName := columnName ( c . Column , i ) tagName := colName fieldName := StructName ( colName , settings ) suffix := 0 if o , ok := suffixes [ c . id ] ; ok { suffix = o } else if v := seen [ colName ] ; v > 0 { suffix = v + 1 } suffixes [ c . id ] = suffix if suffix > 0 { tagName = fmt . Sprintf ( " " , tagName , suffix ) fieldName = fmt . Sprintf ( " " , fieldName , suffix ) } tags := map [ string ] string { } if settings . Go . EmitDBTags { tags [ " " ] = tagName } if settings . Go . EmitJSONTags { tags [ " " ] = tagName } gs . Fields = append ( gs . Fields , Field { Name : fieldName , Type : goType ( r , c . Column , settings ) , Tags : tags , } ) seen [ colName ] ++ } return & gs }
It's possible that this method will generate duplicate JSON tag values
It ' s possible that this method will generate duplicate JSON tag values
// Track suffixes by the ID of the column, so that columns referring to the same numbered parameter can be // reused.