-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdep.go
More file actions
50 lines (42 loc) · 697 Bytes
/
dep.go
File metadata and controls
50 lines (42 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package golang
import (
"go/ast"
"strings"
"github.com/code-visible/golang/utils"
)
type Dep struct {
ID string `json:"id"`
Name string `json:"name"`
Typ string `json:"type"`
Ref string `json:"ref"`
std bool
pkg *Pkg
}
func NewPkgDep(name string, pkg *Pkg) *Dep {
return &Dep{
Name: name,
std: false,
pkg: pkg,
}
}
func NewDep(name string, imp *ast.ImportSpec) *Dep {
importPath := strings.Trim(imp.Path.Value, `"`)
if isStd(importPath) {
return &Dep{
Name: name,
std: true,
}
}
return &Dep{
Name: name,
std: false,
}
}
func (d *Dep) SetupID() {
d.ID = utils.Hash(d.Name)
}
func (d *Dep) SetupRef() {
if d.pkg != nil {
d.Ref = d.pkg.ID
}
}