我想导入Caddy
一个 go 项目,但我似乎无法提出最基本的例子。我尝试拉依赖关系dep
或go mod
两者都失败了。
dep init
No versions of golang.org/x/text met constraints:
v0.3.0: unable to update checked out version: : command failed: [git checkout f21a4dfb5e38f5895301dc265a8def02365cc3d0]: exit status 128
v0.2.0: unable to update checked out version: : command failed: [git checkout c4d099d611ac3ded35360abf03581e13d91c828f]: exit status 128
v0.1.0: unable to update checked out version: : command failed: [git checkout ab5ac5f9a8deb4855a60fab02bc61a4ec770bd49]: exit status 1
master: unable to update checked out version: : command failed: [git checkout fe223c5a2583471b2791ca99e716c65b4a76117e]: exit status 1
release-branch.go1.11: unable to update checked out version: : command failed: [git checkout cb6730876b985e110843c1842a7a63a63677cf08]: exit status 1
release-branch.go1.12: unable to update checked out version: : command failed: [git checkout e6919f6577db79269a6443b9dc46d18f2238fb5d]: exit status 1
go build
(使用 go mod)
go build
go: finding github.com/mholt/caddy/caddyhttp latest
go: finding github.com/jimstudt/http-authentication/basic latest
go: finding github.com/jimstudt/http-authentication latest
go: finding github.com/mholt/certmagic latest
go: finding github.com/flynn/go-shlex latest
go: finding github.com/lucas-clemente/quic-go/h2quic latest
go: finding golang.org/x/net/http2 latest
go: finding golang.org/x/net latest
go: finding github.com/xenolf/lego/certcrypto latest
go: finding github.com/xenolf/lego/challenge latest
go: finding github.com/xenolf/lego/challenge/tlsalpn01 latest
go: finding github.com/lucas-clemente/quic-go-certificates latest
go: finding github.com/cheekybits/genny/generic latest
go: finding github.com/lucas-clemente/aes12 latest
go: finding github.com/bifurcation/mint latest
# github.com/mholt/caddy/caddyhttp/markdown/summary
/home/ciokan/go/pkg/mod/github.com/mholt/caddy@v0.11.5/caddyhttp/markdown/summary/render.go:24:5: cannot use (*renderer)(nil) (type *renderer) as type blackfriday.Renderer in assignment:
*renderer does not implement blackfriday.Renderer (missing RenderFooter method)
/home/ciokan/go/pkg/mod/github.com/mholt/caddy@v0.11.5/caddyhttp/markdown/summary/summary.go:26:44: too many arguments to conversion to blackfriday.Markdown: blackfriday.Markdown(input, renderer literal, 0)
# github.com/lucas-clemente/quic-go/internal/crypto
/home/ciokan/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.10.1/internal/crypto/key_derivation.go:46:37: cs.KeyLen undefined (type mint.CipherSuiteParams has no field or method KeyLen)
/home/ciokan/go/pkg/mod/github.com/lucas-clemente/quic-go@v0.10.1/internal/crypto/key_derivation.go:47:35: cs.IvLen undefined (type mint.CipherSuiteParams has no field or method IvLen)
# github.com/mholt/caddy/caddytls
/home/ciokan/go/pkg/mod/github.com/mholt/caddy@v0.11.5/caddytls/setup.go:174:28: cannot use value (type "github.com/xenolf/lego/certcrypto".KeyType) as type "github.com/go-acme/lego/certcrypto".KeyType in assignment
/home/ciokan/go/pkg/mod/github.com/mholt/caddy@v0.11.5/caddytls/setup.go:354:4: cannot use config.Manager.KeyType (type "github.com/go-acme/lego/certcrypto".KeyType) as type "github.com/xenolf/lego/certcrypto".KeyType in field value
这是一个非常基本的脚本:
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/mholt/caddy"
_ "github.com/mholt/caddy/caddyhttp"
)
func init() {
caddy.SetDefaultCaddyfileLoader("default", caddy.LoaderFunc(loadConfig))
}
func loadConfig(serverType string) (caddy.Input, error) {
contents, err := ioutil.ReadFile(caddy.DefaultConfigFile)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
fmt.Printf("Loading Caddyfile: %s\n", string(contents))
return caddy.CaddyfileInput{
Contents: contents,
Filepath: caddy.DefaultConfigFile,
ServerTypeName: serverType,
}, nil
}
func main() {
caddy.AppName = "MyApp"
caddy.AppVersion = "0.1"
caddyfile, err := caddy.LoadCaddyfile("http")
if err != nil {
panic(err)
}
inst, err := caddy.Start(caddyfile)
if err != nil {
panic(err)
}
inst.Wait()
}
那么我应该如何在我自己的包中使用 Caddy 呢?