Update to use modules

Matt Holt 2019-04-20 01:22:26 -06:00
parent 276449cccd
commit 26ceac8d61

@ -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: 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).
```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:
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 ```go
// This is where other plugins get plugged in (imported) package main
_ "your/plugin/package/path/here"
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()
}
``` ```
5. Make your little main function a Go module: `go mod init mycaddy` (the name doesn't really matter).
For example, to plug in the http.git plugin: 6. Then `go install` will then create your binary at `$GOPATH/bin`, or `go build` will put it in the current directory.
```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.