-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support replacements and customizing the core version; update readme
- Loading branch information
Showing
5 changed files
with
151 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ Stay updated, be aware of changes, and please submit feedback! Thanks! | |
|
||
## Requirements | ||
|
||
- Go installed | ||
- Go modules enabled | ||
- [Go installed](https://golang.org/doc/install) | ||
- [Go modules](https://github.com/golang/go/wiki/Modules) enabled | ||
|
||
|
||
## Command usage | ||
|
@@ -30,31 +30,44 @@ Install the `xcaddy` command with: | |
$ go get -u github.com/caddyserver/xcaddy/cmd/xcaddy | ||
``` | ||
|
||
The `xcaddy` command will use the latest version of Caddy by default. You can customize this for all invocations by setting the `CADDY_VERSION` environment variable. | ||
|
||
As usual with `go` command, the `xcaddy` command will pass through the `GOOS`, `GOARCH`, and `GOARM` environment variables for cross-compilation. | ||
|
||
|
||
### Custom builds | ||
|
||
Syntax: | ||
|
||
``` | ||
$ xcaddy build <caddy_version> | ||
$ xcaddy build [<caddy_version>] | ||
[--output <file>] | ||
[--with <module[@version]>...] | ||
[--with <module[@version][=replacement]>...] | ||
``` | ||
|
||
- `<caddy_version>` is the core Caddy version to build (required, for now). | ||
- `<caddy_version>` is the core Caddy version to build; defaults to `CADDY_VERSION` env variable or latest. | ||
- `--output` changes the output file. | ||
- `--with` can be used multiple times to add plugins by specifying the Go module name and optionally its version, similar to `go get`. | ||
|
||
For example: | ||
Examples: | ||
|
||
```bash | ||
$ xcaddy build v2.0.0-rc.1 \ | ||
$ xcaddy build \ | ||
--with github.com/caddyserver/ntlm-transport | ||
|
||
$ xcaddy build v2.0.1 \ | ||
--with github.com/caddyserver/[email protected] | ||
|
||
$ xcaddy build \ | ||
--with github.com/caddyserver/ntlm-transport=../../my-fork | ||
|
||
$ xcaddy build \ | ||
--with github.com/caddyserver/[email protected]=../../my-fork | ||
``` | ||
|
||
### For plugin development | ||
|
||
If you run `xcaddy` from within the folder of the Caddy plugin you're working on without the `build` subcommand described above, it will build Caddy with your current module and run it, as if you manually plugged it in and ran `go run`. | ||
If you run `xcaddy` from within the folder of the Caddy plugin you're working on _without the `build` subcommand_, it will build Caddy with your current module and run it, as if you manually plugged it in and invoked `go run`. | ||
|
||
The binary will be built and run from the current directory, then cleaned up. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
func TestSplitWith(t *testing.T) { | ||
for i, tc := range []struct { | ||
input string | ||
expectModule string | ||
expectVersion string | ||
expectReplace string | ||
expectErr bool | ||
}{ | ||
{ | ||
input: "module", | ||
expectModule: "module", | ||
}, | ||
{ | ||
input: "module@version", | ||
expectModule: "module", | ||
expectVersion: "version", | ||
}, | ||
{ | ||
input: "module@version=replace", | ||
expectModule: "module", | ||
expectVersion: "version", | ||
expectReplace: "replace", | ||
}, | ||
{ | ||
input: "module=replace", | ||
expectModule: "module", | ||
expectReplace: "replace", | ||
}, | ||
{ | ||
input: "=replace", | ||
expectErr: true, | ||
}, | ||
{ | ||
input: "@version", | ||
expectErr: true, | ||
}, | ||
{ | ||
input: "@version=replace", | ||
expectErr: true, | ||
}, | ||
{ | ||
input: "", | ||
expectErr: true, | ||
}, | ||
} { | ||
actualModule, actualVersion, actualReplace, actualErr := splitWith(tc.input) | ||
if actualModule != tc.expectModule { | ||
t.Errorf("Test %d: Expected module '%s' but got '%s' (input=%s)", | ||
i, tc.expectModule, actualModule, tc.input) | ||
} | ||
if tc.expectErr { | ||
if actualErr == nil { | ||
t.Errorf("Test %d: Expected error but did not get one (input='%s')", i, tc.input) | ||
} | ||
continue | ||
} | ||
if !tc.expectErr && actualErr != nil { | ||
t.Errorf("Test %d: Expected no error but got: %s (input='%s')", i, actualErr, tc.input) | ||
} | ||
if actualVersion != tc.expectVersion { | ||
t.Errorf("Test %d: Expected version '%s' but got '%s' (input='%s')", | ||
i, tc.expectVersion, actualVersion, tc.input) | ||
} | ||
if actualReplace != tc.expectReplace { | ||
t.Errorf("Test %d: Expected module '%s' but got '%s' (input='%s')", | ||
i, tc.expectReplace, actualReplace, tc.input) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters