聊聊dubbo-go-proxy的hostFilter


本文摘自网络,作者,侵删。

本文主要研究一下dubbo-go-proxy的hostFilter

hostFilter

dubbo-go-proxy/pkg/filter/host/host.go

// hostFilter is a filter for host.
type hostFilter struct {
    host string
}

// New create host filter.
func New(host string) filter.Filter {
    return &hostFilter{host: host}
}
hostFilter的New根据host创建hostFilter

Do

dubbo-go-proxy/pkg/filter/host/host.go

func (f hostFilter) Do() fc.FilterFunc {
    return func(c fc.Context) {
        f.doHostFilter(c.(*contexthttp.HttpContext))
    }
}

func (f hostFilter) doHostFilter(c *contexthttp.HttpContext) {
    c.Request.Host = f.host
    c.Next()
}
Do方法执行doHostFilter方法,该方法将f.host设置给c.Request.Host,然后执行c.Next()

httpFilter

dubbo-go-proxy/pkg/proxy/listener.go

func httpFilter(ctx *h.HttpContext, request fc.IntegrationRequest) {
    if len(request.Host) != 0 {
        ctx.AppendFilterFunc(host.New(request.Host).Do())
    }
    if len(request.Path) != 0 {
        ctx.AppendFilterFunc(replacepath.New(request.Path).Do())
    }
}
httpFilter方法通过AppendFilterFunc将host.New(request.Host)追加到Filters中

小结

dubbo-go-proxy的hostFilter将f.host设置给c.Request.Host,然后执行c.Next()。

doc

  • dubbo-go-proxy

本文来自:Segmentfault

感谢作者:.container .card .information strong

查看原文:聊聊dubbo-go-proxy的hostFilter

相关阅读 >>

Golang基础数据类型-浮点型

快看!Go-carbon 1.2.2 版本发布了!新增了时间设置和时间差比较功能

Go - struct{} 实现 interface{}

手撸Golang 基本数据结构与算法 堆排序

Golang指针的使用限制和unsafe.pointer的突破之路

一文读懂云原生 Go-zero 微服务框架

Go 作为脚本语言用

Golang 写个快速排序

prometheus实战---告警模板编写(四)

Go微服务框架Go-micro整体架构介绍

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...