github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/project/govendor/govendor.go (about)

     1  package govendor
     2  
     3  import (
     4  	"encoding/json"
     5  	"io/ioutil"
     6  )
     7  
     8  func LoadGoVendorJSON(p string) (Vendor, error) {
     9  	jsonBytes, err := ioutil.ReadFile(p)
    10  	vendor := Vendor{}
    11  	if err != nil {
    12  		return vendor, err
    13  	}
    14  	json.Unmarshal(jsonBytes, &vendor)
    15  	return vendor, nil
    16  }
    17  
    18  type VendorPackage struct {
    19  	Path         string `json:"path"`
    20  	Revision     string `json:"revision"`
    21  	RevisionTime string `json:"revisionTime"`
    22  	ChecksumSHA1 string `json:"checksumSHA1"`
    23  }
    24  
    25  type Vendor struct {
    26  	Comment  string          `json:"comment"`
    27  	Ignore   string          `json:"ignore"`
    28  	RootPath string          `json:"rootPath"`
    29  	Package  []VendorPackage `json:"package"`
    30  }
    31  
    32  func (v *Vendor) ListImportPath() []string {
    33  	slice := make([]string, 0)
    34  	for _, p := range v.Package {
    35  		path := p.Path
    36  		slice = append(slice, path)
    37  	}
    38  	return slice
    39  }