草庐IT

go - 将 Caddy 导入 go 项目依赖项失败

coder 2024-07-09 原文

我想将 Caddy 导入到一个 go 项目中,但我似乎无法提出最基本的示例。我尝试使用 depgo mod 拉取依赖项,但都失败了。

dep 初始化

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?

最佳答案

你能试试这个吗:

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
)

可能不是最好的解决方案,但我做了什么:

  1. 阅读 vendor 文件夹中的 list https://github.com/mholt/caddy/blob/v0.11.5/vendor/manifest
  2. 为遇到麻烦的导入获取修订
  3. 修改require部分的版本

关于go - 将 Caddy 导入 go 项目依赖项失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55290521/

有关go - 将 Caddy 导入 go 项目依赖项失败的更多相关文章

  1. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  2. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  3. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

  4. ruby-on-rails - 在 ruby​​ .gemspec 文件中,如何指定依赖项的多个版本? - 2

    我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这

  5. ruby - RuntimeError(自动加载常量 Apps 多线程时检测到循环依赖 - 2

    我收到这个错误:RuntimeError(自动加载常量Apps时检测到循环依赖当我使用多线程时。下面是我的代码。为什么会这样?我尝试多线程的原因是因为我正在编写一个HTML抓取应用程序。对Nokogiri::HTML(open())的调用是一个同步阻塞调用,需要1秒才能返回,我有100,000多个页面要访问,所以我试图运行多个线程来解决这个问题。有更好的方法吗?classToolsController0)app.website=array.join(',')putsapp.websiteelseapp.website="NONE"endapp.saveapps=Apps.order("

  6. ruby - 即使失败也继续进行多主机测试 - 2

    我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r

  7. Ruby 从大范围中获取第 n 个项目 - 2

    假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit

  8. ruby - 检查是否通过 require 执行或导入了 Ruby 程序 - 2

    如何检查Ruby文件是否是通过“require”或“load”导入的,而不是简单地从命令行执行的?例如:foo.rb的内容:puts"Hello"bar.rb的内容require'foo'输出:$./foo.rbHello$./bar.rbHello基本上,我想调用bar.rb以不执行puts调用。 最佳答案 将foo.rb改为:if__FILE__==$0puts"Hello"end检查__FILE__-当前ruby​​文件的名称-与$0-正在运行的脚本的名称。 关于ruby-检查是否

  9. ruby-on-rails - 创建 ruby​​ 数据库时惰性符号绑定(bind)失败 - 2

    我正在尝试在Rails上安装ruby​​,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf

  10. ruby - 正则表达式在哪个位置失败? - 2

    我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束

随机推荐