I use this code to get a list of dependencies imported in a single Go source file:
// GetFileImports returns all the imports from the Golang source code file.
func GetFileImports(filepath string) ([]string, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, filepath, nil, parser.ImportsOnly)
if err != nil {
return nil, err
}
imports := make([]string, len(file.Imports))
for i := range file.Imports {
imports[i] = strings.Trim(file.Imports[i].Path.Value, "\"")
}
return imports, nil
}
I get this list:
namoled-core/data
namoled-core/shared
encoding/json
fmt
io/ioutil
log
net/http
github.com/gorilla/mux
github.com/gorilla/websocket
Where namoled-core/data
and namoled-core/shared
are parts of my own project, github.com/gorilla/mux
and github.com/gorilla/websocket
are downloadable dependencies, and all the rest are standard library dependencies. Is there a solid and unambiguous way to distinct dependencies from the current project, downloadable dependencies and standard library dependencies only by their import paths? Taking in account that project path may also be a Github link.