小编Par*_*hwa的帖子

带有 mustEmbedUnimplemented*** 方法的 grpc

最近,grpc-go 引入了 mustEmbedUnimplemented*** 方法。它用于向前兼容。

简单来说,我无法理解它是如何提供帮助的,以及在没有它的情况下我们面临哪些问题?现在在我的结构中,我使用添加以下语句,但是,我不知道为什么...

type server struct {
     pdfpb.UnimplementedGreetServiceServer
}
Run Code Online (Sandbox Code Playgroud)

在 Github 问题 - https://github.com/grpc/grpc-go/issues/3669 中,他们对此进行了辩论,有人可以简单地解释一下它是如何提供帮助的,以及在没有它的情况下我们面临哪些问题?

go protocol-buffers grpc-go

12
推荐指数
3
解决办法
2828
查看次数

无法使用毒蛇解组

我一直试图通过解组我的 json 文件来提取一些 JSON,但是,我不知道为什么它没有发生。我能够使用viper.AllSettings()但不能通过解组来获取数据。我想我犯了一个愚蠢的错误,请分享您的想法。github 链接是 - https://github.com/parthw/100-days-of-code/tree/main/golang/d6-cobra-viper-continued,代码如下。

main.go

package main

import (
    "fmt"

    "example.com/cobra-viper/cmd"
    "github.com/spf13/viper"
)

// Myconfig example
type Myconfig struct {
    username string `mapstructure:"username"`
}

func main() {
    cmd.Execute()
    fmt.Println("I can print this ", viper.AllSettings())
    var mc Myconfig
    if err := viper.Unmarshal(&mc); err != nil {
        fmt.Println(err)
    }
    fmt.Println(mc)
}
Run Code Online (Sandbox Code Playgroud)

在 cmd 目录中使用 cobra CLI 生成的代码:

package cmd

import (
    "fmt"
    "os"

    "github.com/spf13/cobra"

    homedir "github.com/mitchellh/go-homedir"
    "github.com/spf13/viper"
)

var (
    cfgFile string
    author  string
)

// …
Run Code Online (Sandbox Code Playgroud)

go cobra viper-go

1
推荐指数
1
解决办法
1214
查看次数

标签 统计

go ×2

cobra ×1

grpc-go ×1

protocol-buffers ×1

viper-go ×1