mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-25 09:40:13 +08:00
Get module name at runtime, and tidy up modules
This commit is contained in:
parent
b780f0f49b
commit
ccb5d19c25
15
caddy.go
15
caddy.go
|
@ -209,24 +209,23 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
|
||||||
// value will still be returned, but with an
|
// value will still be returned, but with an
|
||||||
// unknown version.
|
// unknown version.
|
||||||
func GoModule() *debug.Module {
|
func GoModule() *debug.Module {
|
||||||
|
mod := &debug.Module{Version: "unknown"}
|
||||||
bi, ok := debug.ReadBuildInfo()
|
bi, ok := debug.ReadBuildInfo()
|
||||||
if ok {
|
if ok {
|
||||||
|
mod.Path = bi.Main.Path
|
||||||
// The recommended way to build Caddy involves
|
// The recommended way to build Caddy involves
|
||||||
// creating a separate main module, which
|
// creating a separate main module, which
|
||||||
// TODO: track related Go issue: https://github.com/golang/go/issues/29228
|
// TODO: track related Go issue: https://github.com/golang/go/issues/29228
|
||||||
for _, mod := range bi.Deps {
|
// once that issue is fixed, we should just be able to use bi.Main... hopefully.
|
||||||
if mod.Path == goModule {
|
for _, dep := range bi.Deps {
|
||||||
return mod
|
if dep.Path == mod.Path {
|
||||||
|
return dep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &debug.Module{Version: "unknown"}
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// goModule is the name of this Go module.
|
|
||||||
// TODO: we should be able to find this at runtime, see https://github.com/golang/go/issues/29228
|
|
||||||
const goModule = "github.com/caddyserver/caddy/v2"
|
|
||||||
|
|
||||||
// CtxKey is a value type for use with context.WithValue.
|
// CtxKey is a value type for use with context.WithValue.
|
||||||
type CtxKey string
|
type CtxKey string
|
||||||
|
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -6,8 +6,6 @@ github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITg
|
||||||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||||
github.com/Masterminds/sprig v2.20.0+incompatible h1:dJTKKuUkYW3RMFdQFXPU/s6hg10RgctmTjRcbZ98Ap8=
|
github.com/Masterminds/sprig v2.20.0+incompatible h1:dJTKKuUkYW3RMFdQFXPU/s6hg10RgctmTjRcbZ98Ap8=
|
||||||
github.com/Masterminds/sprig v2.20.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
github.com/Masterminds/sprig v2.20.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
|
||||||
github.com/andybalholm/brotli v0.0.0-20190430215306-5c318f9037cb h1:Qs8/an94NFS1x2nn7rSI+skKFuw/EGfEYAGS3w/p+jc=
|
|
||||||
github.com/andybalholm/brotli v0.0.0-20190430215306-5c318f9037cb/go.mod h1:+lx6/Aqd1kLJ1GQfkvOnaZ1WGmLpMpbprPuIOOZX30U=
|
|
||||||
github.com/andybalholm/brotli v0.0.0-20190704151324-71eb68cc467c h1:pBKtfXLqKZ+GPHGjlBheGaXK2lddydUG3XhWGrYjxOA=
|
github.com/andybalholm/brotli v0.0.0-20190704151324-71eb68cc467c h1:pBKtfXLqKZ+GPHGjlBheGaXK2lddydUG3XhWGrYjxOA=
|
||||||
github.com/andybalholm/brotli v0.0.0-20190704151324-71eb68cc467c/go.mod h1:+lx6/Aqd1kLJ1GQfkvOnaZ1WGmLpMpbprPuIOOZX30U=
|
github.com/andybalholm/brotli v0.0.0-20190704151324-71eb68cc467c/go.mod h1:+lx6/Aqd1kLJ1GQfkvOnaZ1WGmLpMpbprPuIOOZX30U=
|
||||||
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
|
github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY=
|
||||||
|
|
|
@ -20,8 +20,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/modules/caddyhttp"
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -28,8 +28,8 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/modules/caddyhttp"
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CircuitBreaker defines the functionality of a circuit breaker module.
|
// CircuitBreaker defines the functionality of a circuit breaker module.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user