Go语言中文网 为您找到相关结果 95

Caddy – 方便够用的 HTTPS server 新手教程

最近发现了一个 golang 开发的 HTTP server,叫做 Caddy,它配置起来十分简便,甚至可以 28 秒配置好一个支持 http2 的 server ,而且对各种 http 新特性都支持的比较早(比如 http2、quic都有支持)。 安装 用过 golang 的应该都知道,golang 程序基本上不会有各种依赖,都是光秃秃一个可执行程序,cp 到 /usr/local/bin就算安装完成了,所以说安装 caddy 是很简单的,我给出三种方法。 脚本安装 curl -s https://getcaddy.com | bash caddy 官方给出了一个安装脚本,执行上面的命令就可以一键安装 caddy,等执行结束后,使用 which caddy,可以看到 caddy 已经被安装...阅读全文

博文 2019-04-19 11:34:45 岳永

Caddy 源码全解析

Caddy 源码全解析 Preface Caddy 是 Go 语言构建的轻量配置化服务器。同时代码结构由于 Go 语言的轻便简洁,比较易读,推荐学弟学妹学习 Go 的时候也去查看追一下它的源码。不用怕相信这篇文章能给你很大的信心。 可能会有点多,建议多看几遍。 Overview-CaddyMain 当然,建议看这篇文章的时候,查看上手一下 Caddy 的实际配置操作应用,对理解源码会有好处,如果没有操作过也没有关系。 Package 这是 caddy 包的结构 首先我们从一切的开始讲起,即平时我们程序运行的 main.go 函数。这是 上图 caddy 文件夹下的目录结构。在 caddy 文件夹中的 main 函数启动 caddy 服务器。实际运行的是 run.go 中的文件,这是方便测试使...阅读全文

博文 2019-08-05 00:02:38 yhyddr

如何从单独的容器调试运行中的Docker容器

容器非常适合封装软件,但是有时一味地改造容器镜像以使其尽可能小时,您可能走得太远。我们需要在“简洁”的镜像和无法调试的镜像之间找到很好的平衡。 看到人们调试正在运行的容器的正常方法是docker exec -it $ CONTAINER sh并根据需要在容器中安装调试工具。但是,如果您的容器没有/ bin / sh怎么办?如果没有包管理器怎么办?您可以使用docker cp将实用程序复制到容器中,然后将exec复制到正在运行的容器中,但这也很麻烦。 因此,一个朋友最近没有询问如何从容器中进行调试,而是询问如何从其他容器中进行调试。我没有那么聪明,所以我在网上问了很多聪明的人,并得到了很好的答复。 我们创建一个只有caddy的精简容器。 首先下载/提取caddy二进制文件 $: curl ht...阅读全文

博文 2019-10-19 19:32:54 iyacontrol

Is it possible for a user with no programming knowledge to easily manage content on a Go website?

<p>Are there any tools that would allow say my grandmother to log in to a website as admin and manage her crochet site without needing me for every little change? Or is WordPress/PHP the only obvious option?</p> <hr/>**评论:**<br/><br/>djherbis: <pre><p>It sounds like you want a CMS, it probably doesn&#3...阅读全文

This is a longshot but does anybody happen to know what the Procfile should look like for a Caddy site on Heroku?

<p>There&#39;s a bunch of buildpacks but I can&#39;t find an example of a Procfile anywhere</p> <hr/>**评论:**<br/><br/>DenzelM: <pre><p>Are you having a specific problem? I don&#39;t have any experience with Caddy. But for Heroku you must <a href="https://devcenter.heroku.com/articles/depl...阅读全文

资源 2017-08-14 00:00:07 blov

Can someone point me to a web server written in Go using just net/http (no 3rd party framework)?

<p>Hi all,</p> <p>I&#39;m learning Go these days, and have written a basic one-file web server in Go. I would like to now look at what other people have written, and learn about best practices on structuring code.</p> <p>Specifically, I&#39;m interested in studying a Go project or code example that implements...阅读全文

资源 2016-12-21 18:00:10 blov

caddy(3) 为 caddy 添加一个 反向代理插件

caddy-grpc 为 caddy 添加一个 反向代理插件 项目地址:github.com/yhyddr/cadd… 前言 上一次我们学习了如何在 Caddy 中扩展自己想要的插件。博客中只提供了大致框架。这一次,我们来根据具体插件 caddy-grpc 学习。 选取它的原因是,它本身是一个独立的应用,这里把它做成了一个 Caddy 的插件。或许你有进一步理解到 Caddy 的良好设计。 插件作用 该插件的目的与Improbable-eng/grpc-web/go/grpcwebproxy目的相同,但作为 Caddy 中间件插件而不是独立的Go应用程序。 而这个项目的作用又是什么呢? 这是一个小型反向代理,可以使用gRPC-Web协议支持现有的gRPC服务器并公开其功能,允许从浏览器中使用...阅读全文

博文 2019-08-10 22:34:16 yhyddr

记一次goroutine泄漏问题查找原因与解决

记一次goroutine泄漏问题查找原因与解决 问题描述: 有个需求要实现根据url参数在反向代理负载均衡处分发到不同的k8s service,反向代理负载均衡用的是caddy,于是将caddy源码拉下来,在原来proxy插件的基础上修改成以下idproxy插件,实现根据id参数分发到id-xxx.namespace的k8s服务 func init() { httpserver.RegisterDevDirective("idproxy", "proxy") caddy.RegisterPlugin("idproxy", caddy.Plugin{ ServerType: "http", Action: setup, }) } type Upstream struct { proxy.Ups...阅读全文

博文 2019-07-01 17:49:44 cdongyang

如何为 caddy 添写自定义插件

如何为 caddy 添写自定义插件 项目地址:https://github.com/yhyddr/quicksilver/tree/master/gosample/caddy-plugin 前言 Caddy附带一个HTTP服务器,但是你可以实现其他服务器类型并将它们插入Caddy中。其他类型的服务器可以是SSH、SFTP、TCP、内部使用的其他东西等等。对于Caddy来说,服务器的概念是任何可以Listen()和Serve()的东西。这意味着什么、如何运作都取决于你。你可以自由地发挥你的创造力去使用它。那么怎样去扩展 Caddy 呢?不同的服务器类型,可以根据自己的需要定制不同的插件。我们在这里,通过添加最简单的不做任何事的插件,来熟悉如何扩展 Caddy 服务器。 Plugin for H...阅读全文

博文 2019-08-10 00:02:40 yhyddr

Caddy源码阅读(三)Caddyfile 解析 by Loader & Parser

Caddy源码阅读(三)Caddyfile 解析 by Loader & Parser Preview 前文提到了 Caddy 的启动流程 和 Run 函数,现在我们顺着启动流程的第一步,读取 Caddyfile 的 源码阅读开始。 Loader 概念 可以理解为读取器。 在 caddy 中 由 Loader 执行 装载 配置文件的职能。看一下它的工作流程。 这个图来源于 plugin.go 文件 可以看到这里通过 Loader 解耦了 caddyfile 文件的读取,所以把它放在了 plugin.go 文件中,作为一个插件注册在 caddy app 中。 可以多定义 caddyfileloader 在图中由三个长方形的表示为数组 自定义的 caddyfileloader 会实现 右半部分的...阅读全文

博文 2019-09-02 00:04:17 yhyddr

caddy(四)Run详解

caddy(四)Run详解 前言 平时我们使用 caddy 都是使用 它的 二进制 分发文件,我们现在来分析 caddy 的 Run 函数。从最外层抽象的看它都做了些什么。 Caddy Run 我们来看看 Caddy Run 中引入了哪些包和操作,对 Caddy 的总体行为做一个概览caddy/caddymain/run.go首先看 init 函数 func init() { caddy.TrapSignals() flag.BoolVar(&certmagic.Default.Agreed, "agree", false, "Agree to the CA's Subscriber Agreement") flag.StringVar(&certmagic.Default.CA, "ca"...阅读全文

博文 2019-08-20 22:42:57 yhyddr

Are "plugins" good or not?

<p>I&#39;m a backend engineer from PHP to Go. Back to those days, when I have to compile extensions to <code>.so</code> files and put them in the sepcified path and enable it in the PHP configuration file .. that was totally a nightmare for me.</p> <p>And recently that there&#39;re some news about that you can...阅读全文

资源 2017-01-23 18:00:10 blov

如何为 caddy 添写自定义插件

如何为 caddy 添写自定义插件 项目地址:github.com/yhyddr/quic… 前言 Caddy附带一个HTTP服务器,但是你可以实现其他服务器类型并将它们插入Caddy中。其他类型的服务器可以是SSH、SFTP、TCP、内部使用的其他东西等等。 对于Caddy来说,服务器的概念是任何可以Listen()和Serve()的东西。这意味着什么、如何运作都取决于你。你可以自由地发挥你的创造力去使用它。 那么怎样去扩展 Caddy 呢?不同的服务器类型,可以根据自己的需要定制不同的插件。我们在这里,通过添加最简单的不做任何事的插件,来熟悉如何扩展 Caddy 服务器。 Plugin for HTTP 我们会一步一步构建出一个 HTTP Plugin 的框架,到时候你只需要填充自己处理...阅读全文

博文 2019-08-10 12:34:16 yhyddr

Caddy源码阅读(一)Run详解

Caddy源码阅读(一)Run详解 前言 本次系列会讲解 caddy 整个生命周期涉及到的源码。 平时我们使用 caddy 都是使用 它的 二进制 分发文件,现在来分析 caddy 的 Run 函数。从最外层逻辑看它都做了些什么。 Caddy Run 我们来看看 Caddy Run 中引入了哪些包和操作,对 Caddy 的总体行为做一个概览caddy/caddymain/run.go首先看 init 函数 func init() { caddy.TrapSignals() flag.BoolVar(&certmagic.Default.Agreed, "agree", false, "Agree to the CA's Subscriber Agreement") flag.StringVa...阅读全文

博文 2019-08-20 22:02:39 yhyddr

Embed http.ResponseWriter but retain Pusher/Flusher/Hijacker functionality

<p>What would be a strategy to intercept writes to a http.ResponseWriter but keep all functionality of the original response writer? An example would be middleware that e.g. gzips or minifies any writes to a response writer. A contrived example would be: <a href="https://play.golang.org/p/PZxxLaWu5W" rel="nofollow">https...阅读全文

Why the hell is go suddenly encouraging people to write shared libraries and will it stop ?

<p>I was really excited looking at what changed for go 1.8 until I saw plugins. Which, as far as I can see, are syntactic sugar to help you create shared libraries without getting your hand too dirty.</p> <p>For all its faults, golang has managed to get one thing right... its simple, to this date they&#39;ve managed not to ad...阅读全文