Partial Struct definition

Hi,
I’m working on FB Marketing API and don’t know how to manage properly the Ads Struc.

The Ads is a huge struct and would like to define Partial type of Ads:

  • Single Photo
  • Collection
  • Carousel

For each case, it’s a partial struc of my full Ads Struct. For example for the creative part:


type FacebookCreative struct {
	ObjectStorySpec *FacebookObjectStorySpec `json:"object_story_spec,omitempty"`
	Message         string                   `json:"message,omitempty"`
	Description     string                   `json:"description,omitempty"`
	ImageHash       string                   `json:"image_hash,omitempty"`
	CallToAction    *struct {
		Type string `json:"type,omitempty"`
	} `json:"call_to_action,omitempty"`
	AssetFeedSpec *struct {
		Bodies []struct {
			Text string `json:"text,omitempty"`
		} `json:"bodies,omitempty"`
		Descriptions []struct {
			Text string `json:"text,omitempty"`
		} `json:"descriptions,omitempty"`
		CallToActionTypes []string `json:"call_to_action_types,omitempty"`
		AdFormats         []string `json:"ad_formats,omitempty"`
		OptimizationType  string   `json:"optimization_type,omitempty"`
		Images            []struct {
			Hash string `json:"hash,omitempty"`
		} `json:"images,omitempty"`
		Videos []struct {
			Video string `json:"video_id,omitempty"`
		} `json:"videos,omitempty"`
		LinkURLs []struct {
			WebsiteURL string `json:"website_url"`
		} `json:"link_urls,omitempty"`
		Titles []struct {
			Text string `json:"text"`
		} `json:"titles,omitempty"`
	} `json:"asset_feed_spec,omitempty"`
	ExternalID   string `json:"id,omitempty"`
	Title        string `json:"title,omitempty"`
	Body         string `json:"body,omitempty"`
	ImageURL     string `json:"image_url,omitempty"`
	ThumbnailURL string `json:"thumbnail_url,omitempty"`
	ObjectType   string `json:"object_type,omitempty"`
	ActorType    string `json:"actor_type,omitempty"`
	Name         string `json:"name,omitempty"`
	AccessToken  string `json:"access_token"`
	Status       string `json:"status"`
}

for Collection, I have to remove the ObjectStorySpec par, for single AssetFeedSpec. I would like to define partial type withotu the unecessary fields, but I would liek to be able to use these type at the end for generic method that works for all type of ads…

The only solution I found it to marshal unmarshal into the real type…

any better idea?

Would struct embedding help?

type A struct {
  a int
}

type B struct {
  b int
}

type AndB struct {
  A
  B
}
1 Like

No because I have 10 nested objects inside…