doukeng7426 2019-03-21 23:04
浏览 231
已采纳

将Caddy导入go项目中的依赖项失败

I want to import Caddy into a go project but I can't seem to bring up even the most basic examples. I tried pulling the dependencies with dep or go mod with both failing miserably.

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 (with 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

This is a really basic script:

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
", 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()
}

So how am I supposed to use Caddy in my own package?

  • 写回答

1条回答 默认 最新

  • dtyqeoc70733 2019-03-22 01:55
    关注

    Could you try with this one:

    module stack/cady
    
    go 1.12
    
    require (
        github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115 // indirect
        github.com/cenkalti/backoff v2.1.1+incompatible // indirect
        github.com/cheekybits/genny v1.0.0 // indirect
        github.com/dustin/go-humanize v1.0.0 // indirect
        github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 // indirect
        github.com/google/uuid v1.1.1 // indirect
        github.com/gorilla/websocket v1.4.0 // indirect
        github.com/hashicorp/go-syslog v1.0.0 // indirect
        github.com/hashicorp/golang-lru v0.5.1 // indirect
        github.com/jimstudt/http-authentication v0.0.0-20140401203705-3eca13d6893a // indirect
        github.com/lucas-clemente/aes12 v0.0.0-20171027163421-cd47fb39b79f // indirect
        github.com/lucas-clemente/quic-go v0.10.1-no-integrationtests // indirect
        github.com/lucas-clemente/quic-go-certificates v0.0.0-20160823095156-d2f86524cced // indirect
        github.com/mholt/caddy v0.11.5
        github.com/mholt/certmagic v0.0.0-20190225061201-e3e89d1096d7 // indirect
        github.com/naoina/go-stringutil v0.1.0 // indirect
        github.com/naoina/toml v0.1.1 // indirect
        github.com/russross/blackfriday v0.0.0-20170610170232-067529f716f4 // indirect
        github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
        github.com/xenolf/lego v2.2.1-0.20190304181753-67b329e3e370+incompatible // indirect
        golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53 // indirect
        gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
        gopkg.in/yaml.v2 v2.2.2 // indirect
    )
    

    Probably not the best solution but what I did:

    1. Read the manifest in vendor folder in https://github.com/mholt/caddy/blob/v0.11.5/vendor/manifest
    2. Get the revision for imports in trouble
    3. Modify the version in require part
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口