Created
August 18, 2018 13:25
-
-
Save ysugimoto/8d1f63f2eb1275bb9b39cb1cdd6cded5 to your computer and use it in GitHub Desktop.
list imports example
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" | |
"github.com/satori/go.uuid" | |
"github.com/stretch/testify/assert" | |
) | |
func main() { | |
fmt.Println("vim-go") | |
} |
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/parser" | |
"go/token" | |
"net/url" | |
"strings" | |
) | |
func main() { | |
t := token.NewFileSet() | |
a, err := parser.ParseFile(t, "./example.go", nil, parser.ImportsOnly) | |
if err != nil { | |
panic(err) | |
} | |
for _, i := range a.Imports { | |
p := strings.Trim(i.Path.Value, `"`) | |
fmt.Print(p) | |
u, err := url.Parse(p) | |
if err != nil { | |
fmt.Println("error", err) | |
} else { | |
fmt.Println("succes", u.Host) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment