Skip to content

Unexpected struct naming behavior #125

@derekperkins

Description

@derekperkins

My expectation when setting up my structs is that I would be able to control the Salesforce api name by using a soql, json, or other tag. I don't want my Go structs to have field names like ExternalId__c. It wasn't until I dove into the code and saw extensive use of mapstructure that I realized everything was based on the field name.
https://github.com/k-capehart/go-salesforce/blob/main/dml.go#L178-L183

Today, I could use mapstructure:ExternalId__c as a tag and I would be able to name my struct fields however I want, but that unnecessarily ties the salesforce api to the mapstructure package.
https://pkg.go.dev/github.com/go-viper/mapstructure/v2#hdr-Field_Tags

The decoder config allows you to set your own tag name, so I would propose something like salesforce:"fieldName", e.g.
https://pkg.go.dev/github.com/go-viper/mapstructure/v2#DecoderConfig

type account struct {
	ExternalID string `salesforce:"ExternalId__c"`
	Name       string
}

This is more obvious what the expected behavior is, and doesn't tie the implementation to mapstructure in the future. I thought about soql, but that has too much baggage for other use cases, and mapstructure wouldn't be able to parse it properly. There's a case too for json, but that is probably too overloaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions