Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
/ gomod Public

Package gomod provides a parser for go.mod files; mirror of the official repository https://gitlab.com/tobiaskoch/gomod

License

Notifications You must be signed in to change notification settings

t081as/gomod

Repository files navigation

GoMod

Package gomod provides a parser for go.mod files according to the official specification. Since this package heavily relies on the go command, a go installation is required for this module to work.

The documentation is available here: https://pkg.tk-software.de/gomod

package main

import (
	"fmt"

	"pkg.tk-software.de/gomod"
)

func main() {
	mod, err := gomod.NewFromDir("./testdata/default/")
	if err != nil {
		return
	}

	fmt.Println("Module path:", mod.Module.Path)
	fmt.Println("Go version:", mod.Go)
	fmt.Println()

	fmt.Println("Required:")
	for _, r := range mod.Require {
		if !r.Indirect {
			fmt.Printf("%s@%s\n", r.Path, r.Version)
		}
	}
	fmt.Println()

	fmt.Println("Required (indirect):")
	for _, r := range mod.Require {
		if r.Indirect {
			fmt.Printf("%s@%s\n", r.Path, r.Version)
		}
	}
	fmt.Println()

	fmt.Println("Replaced:")
	for _, r := range mod.Replace {
		if r.Old.Version != "" {
			fmt.Printf("%s@%s -> %s@%s\n", r.Old.Path, r.Old.Version, r.New.Path, r.New.Version)
		} else {
			fmt.Printf("%s -> %s\n", r.Old.Path, r.New.Path)
		}
	}
	fmt.Println()

	fmt.Println("Excluded:")
	for _, e := range mod.Exclude {
		fmt.Printf("%s@%s\n", e.Path, e.Version)
	}
	fmt.Println()

	fmt.Println("Retracted:")
	for _, r := range mod.Retract {
		if r.Low == r.High {
			fmt.Printf("%s: %s\n", r.Low, r.Rationale)
		} else {
			fmt.Printf("[%s, %s]: %s\n", r.Low, r.High, r.Rationale)
		}
	}
	fmt.Println()
}

Contributing

see CONTRIBUTING.md

Donating

Thanks for your interest in this project. You can show your appreciation and support further development by donating.

License

GoMod © 2023-2024 Tobias Koch. Released under a BSD-style license.

About

Package gomod provides a parser for go.mod files; mirror of the official repository https://gitlab.com/tobiaskoch/gomod

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages