gomod

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFullImportPath

func GetFullImportPath(startAt string) (string, error)

GetFullImportPath resolves the full Go import path for any file or directory within a Go module. Returns the complete import path like "github.com/user/repo/pkg".

startAt can be either:

  • A Go source file path (e.g., "/path/to/project/main.go")
  • A directory path (e.g., "/path/to/project/pkg")
  • An absolute or relative path

Returns an error if:

  • No go.mod found in the directory tree
  • go.mod is malformed or missing module directive
  • Path resolution fails
Example (Directory)
package main

import (
	"fmt"
	"log"

	"github.com/cweill/gotests/internal/gomod"
)

func main() {
	// Get import path for a package directory
	importPath, err := gomod.GetFullImportPath(".")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(importPath)
}
Output:
github.com/cweill/gotests/internal/gomod
Example (File)
package main

import (
	"fmt"
	"log"

	"github.com/cweill/gotests/internal/gomod"
)

func main() {
	// Get import path for a specific Go file
	importPath, err := gomod.GetFullImportPath("gomod.go")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(importPath)
}
Output:
github.com/cweill/gotests/internal/gomod
Example (ModuleRoot)
package main

import (
	"fmt"
	"log"

	"github.com/cweill/gotests/internal/gomod"
)

func main() {
	// Get import path for the module root directory
	importPath, err := gomod.GetFullImportPath("../..")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(importPath)
}
Output:
github.com/cweill/gotests

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL