From ff13dbee28d2033a96806ccce731ac1a76efb90c Mon Sep 17 00:00:00 2001 From: Meghan Date: Mon, 9 Nov 2020 14:51:34 -0800 Subject: [PATCH] add modfile struct --- modfile.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 modfile.go diff --git a/modfile.go b/modfile.go new file mode 100644 index 0000000000000000000000000000000000000000..593bf1a4b74a871d784a59a0b2ffebf56f5354a6 --- /dev/null +++ b/modfile.go @@ -0,0 +1,49 @@ +package main + +import ( + "io/ioutil" + "os" + "strings" + + "github.com/nektro/go-util/util" + "gopkg.in/yaml.v2" +) + +// ModFile is +type ModFile struct { + Name string `yaml:"name"` + Main string `yaml:"main"` + Deps []Dep `yaml:"dependencies"` +} + +// this is the string enum because Go doesnt have those +var ( + DepTypeGit = "git" + AllDepTypes = []string{ + DepTypeGit, + } +) + +// Dep is +type Dep struct { + Type string `yaml:"type"` + Path string `yaml:"path"` +} + +func (s *Dep) cleanPath() string { + p := s.Path + p = strings.TrimPrefix(p, "https://") + p = strings.TrimPrefix(p, "http://") + p = strings.TrimSuffix(p, ".git") + p = strings.Join(strings.Fields(strings.Join(strings.Split(p, "/"), " ")), "/") + return p +} + +func readModFile(fpath string) *ModFile { + f, err := os.Open(fpath) + util.DieOnError(err) + bys, _ := ioutil.ReadAll(f) + m := new(ModFile) + yaml.Unmarshal(bys, &m) + return m +} -- 2.54.0