Skip to content

Instantly share code, notes, and snippets.

@ik5
Last active August 29, 2015 14:18
Show Gist options
  • Save ik5/165843a797b7eca5d64a to your computer and use it in GitHub Desktop.
Save ik5/165843a797b7eca5d64a to your computer and use it in GitHub Desktop.
Example on how to add items to a list based on struct
package main
import "fmt"
type SiteList struct {
Title string
Address string
FeedAddress string
Author string
}
var list = []SiteList{}
func main() {
list = append(list, SiteList{"Blog",
"https://blog.example.com",
"https://blog.example.com/feed/",
"John Doe",
})
fmt.Printf("%v\n", list)
}
package main
import "fmt"
type SiteList struct {
Title string
Address string
FeedAddress string
Author string
}
func fnc(list *[]SiteList) {
*list = append(*list, SiteList{"Blog",
"https://blog.example.com",
"https://blog.example.com/feed/",
"John Doe"})
fmt.Printf("list: %v\n", list)
}
func main() {
list := []SiteList{}
fnc(&list)
fmt.Printf("%v\n", list)
}
package main
import (
"fmt"
"time"
)
type SiteList struct {
Title string
Address string
FeedAddress string
Author string
}
func fnc(list *[]SiteList) {
*list = append(*list, SiteList{"Blog",
"https://blog.example.com",
"https://blog.example.com/feed/",
"John Doe"})
fmt.Printf("list: %v\n", list)
}
func main() {
list := map[time.Time][]SiteList{}
current := time.Now()
site := list[current]
fnc(&site)
list[current] = site
fmt.Printf("%v\n", list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment