Importing local module for development

Hello, I am working on modifying the caddy-l4 module and would like to test my changes locally. I’ve built Caddy from source, and see where I can import custom modules in main.go.

package main

import (
	caddycmd ""

	// plug in Caddy modules here
	_ "../../modules/caddy-l4"

	_ ""

func main() {

However, I’m not sure now to import a local module. Is there a way to do this? Or should I be pointing the import to a github fork of the module?

1 Like

You can import a local Go module using replace in your go.mod:

replace => ../project

Or something like that. (Your local module will still need a go.mod with an import path as if it was published, even if it’s not.)

However, if you’re using xcaddy, it does this for you. All you have to do is run xcaddy inside your module folder instead of caddy. It will compile the current folder as a module into Caddy and run it. (So, for example, you’ll often do xcaddy run instead of caddy run.)


This topic was automatically closed after 30 days. New replies are no longer allowed.