Skip to content

cloudingcity/gomod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gomod

Build Status codecov

Parse go.mod into a struct

Install

go get -u github.com/cloudingcity/gomod

Example

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)
}

Struct

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
}