Go module with local package folders

A basic go module called example with additional handlers and data packages, which doesn’t require Git.

The key point is that a Go module that isn’t a source repo can be created, which enables local subfolders to be used as packages. This may be obvious to Go developers (as it is to me too…now), but I had to work it out the first time I created a Go project independent of my GitHub.

  - abc.go
  - xyz.go


Run this from the command line to generate.

$ go mod init example
module example

go 1.17Code language: JavaScript (javascript)


package main

import example/handlers

...Code language: JavaScript (javascript)


package handlers

import example/data

...Code language: JavaScript (javascript)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.