Having two types:
type Headers []HeaderItem
type HeaderItem struct { // This one doesn't really matter. Could be any other type
Name string
Value string
}
I would like to add a function with the slice as receiver. How can I do something like this (pseudo-code):
func (h *Headers) AddHeaderItem(item HeaderItem) {
h = &(append( *h, item ))
}
The compiler complains about it, so this doesn't work.
I tried:
func (h Headers) AddHeaderItem(item HeaderItem) {
h = append( h, item )
}
This actually compiles but doesn't do what I want: when later on range
ing over the items, I get an empty result.