Giter VIP home page Giter VIP logo

Comments (12)

swiftslee avatar swiftslee commented on July 30, 2024 1

if gen.Name.Name == "initInternalMux" && version == "1" {

确实是个 bug。你愿意看这些代码真是难能可贵呀 👍

这可能是我在社区发现的第一个bug:astonished:

from sniper.

taoso avatar taoso commented on July 30, 2024

你执行 go run main.go falsework rpc --service=foo 试试

from sniper.

swiftslee avatar swiftslee commented on July 30, 2024

有没有完整点的示例?

go run cmd/sniper/main.go rpc --service=hello
执行了这个命令以后 会在rpc/hello/v1/下面生成 proto定义文件 以及相应的pb.go pb.twirp.go文件
之后需要在cmd/server/http.go下面注册你的服务 参考这几行关键的代码

func initMux(mux *http.ServeMux) {
{ //初始化你的server 并且你需要实现你自己的server的方法
server := &helloserver1.Server{}
//加入hooks主要是为了获取请求id和打日志
handler := hello_v1.NewHelloServer(server, hooks)
//这里与官方自带的http包那里比较类似 只是调用http.Handle的时候用了default.mux.Handle
//我理解就是注册了一个http服务
mux.Handle(hello_v1.HelloPathPrefix, handler)}
}

from sniper.

taoso avatar taoso commented on July 30, 2024

之后需要在cmd/server/http.go下面注册你的服务

这个现在会自动注册了

from sniper.

Angel-fund avatar Angel-fund commented on July 30, 2024

服务注册之后initMux会自会自动填充, 但initInternalMux 还是个空函数, 也是能处理initMux的请求,不太清楚这个对内服务用在什么场景?系统内部服务间的调用吗,这个内部服务端口是不暴露给外面吗, 文档上好像没怎么说 initInternalMux用在什么场景,文档上只留了一个空函数有点疑惑

from sniper.

swiftslee avatar swiftslee commented on July 30, 2024

之后需要在cmd/server/http.go下面注册你的服务

这个现在会自动注册了

啊 对~都是命令行自动注册的 我是把自动注册的代码复制过来的👿

from sniper.

Angel-fund avatar Angel-fund commented on July 30, 2024

之后需要在cmd/server/http.go下面注册你的服务

这个现在会自动注册了

啊 对~都是命令行自动注册的 我是把自动注册的代码复制过来的

变化太快,一下从刀耕火种时代进入21世纪文明世界

from sniper.

swiftslee avatar swiftslee commented on July 30, 2024

服务注册之后initMux会自会自动填充, 但initInternalMux 还是个空函数, 也是能处理initMux的请求,不太清楚这个对内服务用在什么场景?系统内部服务间的调用吗,这个内部服务端口是不暴露给外面吗, 文档上好像没怎么说 initInternalMux用在什么场景,文档上只留了一个空函数有点疑惑

我看了下自动注册的命令参数
Cmd.Flags().StringVar(&rootDir, "root", wd, "项目根目录")
Cmd.Flags().StringVar(&rootPkg, "package", "sniper", "项目总包名")
Cmd.Flags().StringVar(&server, "service", "", "服务名")
Cmd.Flags().StringVar(&version, "version", "1", "服务版本")
Cmd.Flags().BoolVar(&needLogin, "need-login", false, "是否校验登录态")
这里对于注册为内部服务并没有可选项 因此我理解应该是不会自动注册内部服务 需要你自己手动去实现
我理解这里的内部接口就是只能内部调用吧 就算暴露了端口 外部也不能访问的 其实我觉得这个功能更适合在网关层去做?类似于大佬说的未来一定是service mesh的时代 不知道大佬怎么看 @lvht

from sniper.

taoso avatar taoso commented on July 30, 2024

这个没有写清楚。我们这边 version 取 0 才会注册到 internal

from sniper.

taoso avatar taoso commented on July 30, 2024

其实我觉得这个功能更适合在网关层去做

@yuswift 我们这边网关是 slb 功能比较简单。我们又是单仓库,内外接口在一个项目,所以引入了这个 internal。你们不需要的话不创建 version=0 的服务就好了。

from sniper.

swiftslee avatar swiftslee commented on July 30, 2024

这个没有写清楚。我们这边 version 取 0 才会注册到 internal

我看了下您那边的逻辑
if gen.Name.Name == "initMux" && version == "0" {
continue
}
if gen.Name.Name == "initInternalMux" && version == "1" {
continue
}
我感觉如果是version==“2”的话,内外服务都会注册吧?我理解v2 和v1都应该一样 只注册initMux吧,不知道这是否是一个bug呢

from sniper.

taoso avatar taoso commented on July 30, 2024

if gen.Name.Name == "initInternalMux" && version == "1" {

确实是个 bug。你愿意看这些代码真是难能可贵呀 👍

from sniper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.