Skip to content

Instantly share code, notes, and snippets.

@tenntenn
Last active November 23, 2019 23:22
Show Gist options
  • Save tenntenn/01703a8417bdb4de901fe3cddc75df9d to your computer and use it in GitHub Desktop.
Save tenntenn/01703a8417bdb4de901fe3cddc75df9d to your computer and use it in GitHub Desktop.
Goを学びたての人が誤解しがちなtypeと構造体について #golang ref: https://qiita.com/tenntenn/items/45c568d43e950292bc31
struct {
Name string
Age int
}
struct {
Name string
Age int
}
var person struct {
Name string
Age int
}
var person struct {
Name string
Age int
}
var ns []int
var m map[string]int
var ns []int
var m map[string]int
var person struct {
Name string
Age int
}
var person struct {
Name string
Age int
}
VarDecl = "var" ( VarSpec | "(" { VarSpec ";" } ")" ) .
VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
func (h Hex) String() string {
return fmt.Sprint("%x", int(h))
}
func (h Hex) String() string {
return fmt.Sprint("%x", int(h))
}
type Hex int
func (h Hex) String() string {
return fmt.Sprint("%x", int(h))
}
type Hex int
func (h Hex) String() string {
return fmt.Sprint("%x", int(h))
}
type Func func() string
func (f Func) String() string {
return f()
}
type Func func() string
func (f Func) String() string {
return f()
}
var person struct {
Name string
Age int
}{
Name: "tenntenn",
Age: 30,
}
var person struct {
Name string
Age int
}{
Name: "tenntenn",
Age: 30,
}
person.Name = "Takuya Ueda"
person.Name = "Takuya Ueda"
TypeDecl = "type" ( TypeSpec | "(" { TypeSpec ";" } ")" ) .
TypeSpec = identifier Type .
TypeDecl = "type" ( TypeSpec | "(" { TypeSpec ";" } ")" ) .
TypeSpec = identifier Type .
Type = TypeName | TypeLit | "(" Type ")" .
TypeName = identifier | QualifiedIdent .
Type = TypeName | TypeLit | "(" Type ")" .
TypeName = identifier | QualifiedIdent .
QualifiedIdent = PackageName "." identifier .
QualifiedIdent = PackageName "." identifier .
type Hex int
type Hex int
type MyReader io.Reader
type MyReader io.Reader
TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
SliceType | MapType | ChannelType .
TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType |
SliceType | MapType | ChannelType .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment