golang const 的 grpc 原型是什么?
What is the grpc proto for golang const?
如果我有golang
type Animal string
const (
Cat Animal = "cat"
Dog Animal = "dog"
Mouse Animal = "mouse"
)
原型应该怎么写?如果我使用枚举,那么我需要手动映射自己吗?
enum Animal {
CAT = 0;
DOG = 1;
MOUSE = 2;
}
您可以像这样动态访问:
import (
"fmt"
pb "animal"
)
func main() {
type Animal string
const (
Cat Animal = "CAT"
Dog Animal = "DOG"
Mouse Animal = "MOUSE"
)
myProtoAnimal := pb.Animal(pb.Animal_value[string(Cat)])
fmt.Printf("%T=%v", myProtoAnimal, myProtoAnimal)
}
将打印
animal.Animal=CAT
如果我有golang
type Animal string
const (
Cat Animal = "cat"
Dog Animal = "dog"
Mouse Animal = "mouse"
)
原型应该怎么写?如果我使用枚举,那么我需要手动映射自己吗?
enum Animal {
CAT = 0;
DOG = 1;
MOUSE = 2;
}
您可以像这样动态访问:
import (
"fmt"
pb "animal"
)
func main() {
type Animal string
const (
Cat Animal = "CAT"
Dog Animal = "DOG"
Mouse Animal = "MOUSE"
)
myProtoAnimal := pb.Animal(pb.Animal_value[string(Cat)])
fmt.Printf("%T=%v", myProtoAnimal, myProtoAnimal)
}
将打印
animal.Animal=CAT