Adding another item to nasted struct

Hi

my struct is like:

type WorkI struct {
	Create Create `json:"create"`
}

type Create struct {
	TicketNoteRequest TicketNoteRequest `json:"ticketNoteRequest"`
}

type TicketNoteRequest struct {
	Author         interface{}   `json:"author"`
	Text           string        `json:"text"`
	Attachments    []Attachments `json:"attachments"`
	AdditionalData []Ad          `json:"additionalData"`
}

type Attachments struct {
	Author         interface{} `json:"author"`
	Name           string      `json:"name"`
	DocumentLink   interface{} `json:"documentLink"`
	Attachment     Attachment  `json:"attachment"`
	Content        string      `json:"content"`
	AdditionalData interface{} `json:"additionalData"`
}

type Attachment struct {
	AttachmentSummary AttachmentSummary `json:"attachmentSummary"`
}

type AttachmentSummary struct {
	Name          string      `json:"name"`
	ContentType   interface{} `json:"contentType"`
	ContentID     interface{} `json:"contentId"`
	ContentLength int         `json:"contentLength"`
}

I am initializing it like:

 data = WorkI{
    			Create: Create{
    				TicketNoteRequest: TicketNoteRequest{
    					Attachments: []Attachments{
    						{
    							Name: t.Num1.FileName,
    							Attachment: Attachment{
    								AttachmentSummary: AttachmentSummary{
    									Name: t.Num1.Content,
    								},
    							},
    							Content: "123213213213213",
    						},
    					},
    				},
    			},
    		}

I need to know how to add another attachment in Attachments, so that i do not have to initialize whole struct again?

tnx
miha

Hi

c.Attachments = append(c.Attachments, newAttachment)

Where newAttachment is one you want to add to the existing attachments

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.