Last active
August 29, 2015 14:18
-
-
Save ik5/165843a797b7eca5d64a to your computer and use it in GitHub Desktop.
Example on how to add items to a list based on struct
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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