First time asking a question! I am trying to separate my development and production that use the same struct.
I am working with Airtable, which sends records as a JSON with an fld tag that we use when unmarshaling.
type AirtableRecord struct {
Name *string `json:"fldAAAA,omitempty"`
}
I have 2 separate Airtables:
- For development
- For production
They are identical, except because of how Airtable works the fields are given different fld tags
Right now to separate development env from production env, I have to uncomment the right members depending which Airtable I am pointing to.
type AirtableRecord struct {
// Development
Name *string `json:"fldAAAA,omitempty"`
// Production
//Name *string `json:"fldBBBB,omitempty"`
}
I keep this type in it's own model.go file, that other packages use.
I have looked into:
- Having multiple JSON tags in a line, Golang doesn't do this
type AirtableRecord struct {
// Development or Production
Name *string `json:"fldAAAA,fldBBBB,omitempty"`
}
- Separating my files using build tags, maybe this works but I'm doing it wrong
File 1:
// +build dev
type AirtableRecord struct {
// Development
Name *string `json:"fldAAAA,omitempty"`
}
File 2:
type AirtableRecord struct {
// Production
Name *string `json:"fldBBBB,omitempty"`
}
- Looked into using retag, but the examples they gave don't look like what I'm looking for
I want to change this Member's tag dynamically based on if I'm running in development mode or production mode.
Any and all help would be appreciated!