Skip to content

Instantly share code, notes, and snippets.

@ysugimoto

ysugimoto/example.go

Created Aug 18, 2018
Embed
What would you like to do?
list imports example
package main
import (
"fmt"
"github.com/satori/go.uuid"
"github.com/stretch/testify/assert"
)
func main() {
fmt.Println("vim-go")
}
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
You can’t perform that action at this time.