Sqlx scan only structure fieldd

I have query which is having 15 columns. Which is written by dba team.

Rest api team like to give only 5 column to front end developer.

But sqlx scan it select ask for all columns.

How to avoid this case.

You could create a struct that’s a subset of those columns:

type WideStruct struct {
	ColumnIDontCareAbout int
	ColumnIDoCareAbout   int
	//...
}

func (w WideStruct) ToSubStruct() SubStruct {
	return SubStruct{
		ColumnIDoCareAbout: w.ColumnIDoCareAbout,
	}
}

type SubStruct struct {
	ColumnIDoCareAbout int
	//...
}

The other easy option is: just use a custom MarshalJson:

You could also ditch sqlx for this query, and scan into local variables and just populate the properties you need on some struct.