If C has:
char *str[20];
Go has
str [10]*string
unlike C, booleans will default false, floats to zero, strings to empty string.
var ageofUniverse int defaults to zero.
You could assign a value that type is inferred ageofUniverse := 14e9
var (
ageofUniverse int
lang = "go"
)
var ageofuniverse uint64
ageofuniverse = 1382000000
foo, bar := 1,2 foo, bar = bar, foo
Go is not exactly object oriented, but structs allow us to define types with fields and methods belonging to them.
type Article struct {
Id string `json:"id"`
Title string `json:"title"`
Desc string `json:"desc"`
Content string `json:"content"`
}
func (a Article) FormatArticle() {
fmt.Printf("[%s] %s - %s\n", a.Id, a.Title, a.Desc)
}