Check Go Module Path Validity

The Go module path enforces certain restrictions as expected on what constitutes a valid path. Try running go mod init for example.

Now, what if you as a Go programmer needed to run this check yourself? That’s where the package comes in. It has a number of functions, one of them being the CheckPath function, which you can use as follows:

// Using Go 1.16
package main

import (

func main() {
	err := module.CheckPath("")
	fmt.Printf("%v\n", err)

Running the above will print an error as the module path is invalid:

malformed module path "https/": missing dot in first path element

Here’s a Playground link.

Initially i thought, it was just because https:// was a protocol specifier, but the restrictions are broader, so always great to be able to do that using the package.