-
-
Save roscopecoltran/52f435016c3851dc4dd9e6fac83a5a02 to your computer and use it in GitHub Desktop.
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" | |
"go/ast" | |
"go/parser" | |
"go/token" | |
"log" | |
) | |
func main() { | |
fs := token.NewFileSet() | |
f, err := parser.ParseFile(fs, "gopher.go", nil, 0) | |
if err != nil { | |
log.Fatal(err) | |
} | |
ast.Inspect(f, func(n ast.Node) bool { | |
switch n := n.(type) { | |
case *ast.Ident: | |
if n.Name == "gopher" { | |
fmt.Println(fs.Position(n.Pos())) | |
} | |
// TODO: caseを追加する | |
} | |
return true | |
}) | |
} |
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 Gopher struct { | |
gopher string `json:"gopher"` | |
} | |
func main() { | |
const gopher = "GOPHER" | |
gogopher := GOPHER() | |
gogopher.gopher = gopher | |
fmt.Println(gogopher) | |
} | |
func GOPHER() (gopher *Gopher) { | |
gopher = &Gopher{ | |
gopher: "gopher", | |
} | |
return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment