From 26ceac8d6184f8c5f0d2282e92ec9f3bfe56e88b Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Sat, 20 Apr 2019 01:22:26 -0600 Subject: [PATCH] Update to use modules --- Plugging-in-Plugins-Yourself.md | 47 +++++++++++++++------------------ 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/Plugging-in-Plugins-Yourself.md b/Plugging-in-Plugins-Yourself.md index b6e9f9d..d20d456 100644 --- a/Plugging-in-Plugins-Yourself.md +++ b/Plugging-in-Plugins-Yourself.md @@ -1,29 +1,24 @@ -You can build Caddy from source and plug in plugins without having to use the build server. You just need [Go installed](https://golang.org/doc/install). Then get this repo by running: - -```bash -$ go get github.com/mholt/caddy/caddy -``` - -It will be saved in a subfolder of `$GOPATH/src`. (Default GOPATH is `$HOME/go`). - -Simply open `caddy/caddymain/run.go` and add an import at the top of the file, to the package of the plugin you're installing: +You can build Caddy from source and plug in plugins without having to use the build server and without changing Caddy's source code! You need [Go installed](https://golang.org/doc/install). +1. [Install Go](https://golang.org/doc/install) if you don't have it already. +2. Set the transitional environment variable for Go modules: `export GO111MODULE=on` +3. Create a new folder anywhere (doesn't have to be in `$GOPATH`) - naming it `caddy` is preferred. +4. Put this Go file into it, modifying it to import the plugins you want: ```go - // This is where other plugins get plugged in (imported) - _ "your/plugin/package/path/here" +package main + +import ( + "github.com/mholt/caddy/caddy/caddymain" + + // plug in plugins here, for example: + // _ "import/path/here" +) + +func main() { + // optional: disable telemetry + // caddymain.EnableTelemetry = false + caddymain.Run() +} ``` - -For example, to plug in the http.git plugin: - - -```go - _ "github.com/abiosoft/caddy-git" -``` - -Then on the command line in that same folder, run: - -```bash -$ go run build.go -``` - -The custom binary will be saved in that folder as `caddy` which you can run. \ No newline at end of file +5. Make your little main function a Go module: `go mod init mycaddy` (the name doesn't really matter). +6. Then `go install` will then create your binary at `$GOPATH/bin`, or `go build` will put it in the current directory.