我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

是否可以通过Golang中的枚举类型反映出枚举变量

For example, I have an enum like:

type Status int

const (
     Normal Status = itoa
     Blocked 
)

The type of Status is known, can I get the "Normal" and "Blocked" by Status. If there is one way, I think it will be by reflect.

I do not want to use mapping to solve it. Because this function is used in a library. it is kind of stateless.

Is there any other ways?

Thanks

Constant names are not exposed in the reflect API.

Use the stringer tool.

近期文章

  • Golang界面和实型
  • appengine应用程式部署-错误:必须至少提供一个处理常式
  • 多次执行例程的一个障碍
  • 如何实现自己的文件类型?
  • SMTP连接读取欢迎消息
  • 限制特定模式的正则表达式字符串长度
  • 如何将日志从单独的程序包写入单独的文件
  • Opengl模型矩阵拉伸顶点
  • 如何防止Go程序因意外恐慌而崩溃?
  • 使用无服务器框架的AWS Codebuild Golang Lambda
  • 无法使用python客户端连接到go grpc服务器
  • 如何在Go中实现零散的配置文件验证
  • 进行反思恐慌:使用interface {}作为类型进行呼叫
  • 由C数组支持切片[重复]
  • LDAP搜索ContextCSN
  • 第一次运行后,go-sdl2不清除窗口表面
  • 如何仅在go-flag包中显示当前设置?
  • 使用Go Routines将控制台日志连续打印到网页的屏幕上
  • Mux或http.HandleFunc都无法在Google App Engine上用于helloworld端点
  • 为指针类型的字段分配值的简捷方式是什么?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华