Init it
go mod init github.com/yingshaoxo/my_package
Create a sub module
mkdir sub_module_folder
cd sub_module_folder
touch sub_module_file.go
# sub_module_file.go
package sub_module
import "fmt"
func Print_something() {
fmt.Println("yingshaoxo is something!")
}
Import and use it in the main package
cd ..
touch main.go
# main.go
package main
import (
sub_module "github.com/yingshaoxo/my_package/sub_module_folder"
)
func main() {
sub_module.Print_something()
}
Run it
go run main.go
More info and example
https://github.com/yingshaoxo/minimum-golang-package-layout