Keep your code in GOPATH which is typically ~/go/src/ Make a subdirectory for the extra package you want:

├── go.mod
├── go.sum
├── main.go
└── mypackage
    └── mypackage.go

In mypackage (make sure to capitalize anything you want to export):

package mypackage

func Double(a int) int {
	return a * 2

Now in main.go you can import the package:

package main

import (


func main() {
	num := mypackage.Double(2)
	output := print.Format(num)



go mod init
go mod tidy

When you upload this to github, others will be able to import mypackage via the same import line