Parse go.mod
into a struct
go get -u github.com/cloudingcity/gomod
package main
import (
"fmt"
"io/ioutil"
"github.com/cloudingcity/gomod"
)
func main() {
file, err := ioutil.ReadFile("go.mod")
if err != nil {
panic(err)
}
mod, err := gomod.Parse(file)
if err != nil {
panic(err)
}
fmt.Printf("%+v", mod)
}
type Module struct {
Path string
Version string
}
type GoMod struct {
Module Module
Go string
Require []Require
Exclude []Module
Replace []Replace
}
type Require struct {
Path string
Version string
Indirect bool
}
type Replace struct {
Old Module
New Module
}