聊聊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

本文来自:51CTO博客

感谢作者:mb601a5cdeee340

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

相关阅读 >>

test

Golang不规则json解析

Go-grpc-rest环境搭建

用 wasmedge 中的嵌入式 webassembly 函数扩展 Golang 应用程序

基本操作:Go创建graphql api

手撸Golang Go与微服务 saga模式之4

Golang学习笔记--unsafe.pointer和uintptr

Go 为什么这么“快”

关于Golang的那些事(八)-- 使用共享变量实现并发

一文搞懂如何实现 Go 超时控制

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




打赏

取消

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

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

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

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

评论

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