authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-09 14:51:34 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-09 14:51:34 -08:00
logff13dbee28d2033a96806ccce731ac1a76efb90c
tree125864548f53bb235d19849878aa3e20e74d08bc
parent1a59a50bf17a91e1b089af71814bc6e9c02f6b8c

add modfile struct


1 files changed, 49 insertions(+), 0 deletions(-)

modfile.go created+49
......@@ -0,0 +1,49 @@
1package main
2
3import (
4 "io/ioutil"
5 "os"
6 "strings"
7
8 "github.com/nektro/go-util/util"
9 "gopkg.in/yaml.v2"
10)
11
12// ModFile is
13type ModFile struct {
14 Name string `yaml:"name"`
15 Main string `yaml:"main"`
16 Deps []Dep `yaml:"dependencies"`
17}
18
19// this is the string enum because Go doesnt have those
20var (
21 DepTypeGit = "git"
22 AllDepTypes = []string{
23 DepTypeGit,
24 }
25)
26
27// Dep is
28type Dep struct {
29 Type string `yaml:"type"`
30 Path string `yaml:"path"`
31}
32
33func (s *Dep) cleanPath() string {
34 p := s.Path
35 p = strings.TrimPrefix(p, "https://")
36 p = strings.TrimPrefix(p, "http://")
37 p = strings.TrimSuffix(p, ".git")
38 p = strings.Join(strings.Fields(strings.Join(strings.Split(p, "/"), " ")), "/")
39 return p
40}
41
42func readModFile(fpath string) *ModFile {
43 f, err := os.Open(fpath)
44 util.DieOnError(err)
45 bys, _ := ioutil.ReadAll(f)
46 m := new(ModFile)
47 yaml.Unmarshal(bys, &m)
48 return m
49}