基于ectd实现go的服务注册
gin支持prometheus

golang实现枚举类型

妙音 posted @ 2022年7月25日 10:50 in golang with tags golang , 708 阅读

描述

 
golang无枚举类型, 但可以借助自定义类型实现
 

什么是枚举类型

 
枚举类型是一种类型, 它的值只有有限个. 换而言之, 枚举类型=一个类型+N个离散值
 
go的实现, 可以自定义一个类型, 把它作为枚举类型, 然后使用该类型定义N个常量.
 
 

示例

 
type FormatType int

const (
    FTByte FormatType = iota
    FTArray
    FTDefine
)

func (ft FormatType) String() string {
    switch ft{
    case FTByte:
        return "byte"
    case FTArray:
        return "array"
    case FTDefine:
        return "define"
    }
    return ""
}
 
 
Avatar_small
six components of he 说:
2023年8月09日 16:34

I can't wait to share this post with my colleagues. It's a goldmine of insights.

Avatar_small
Johny 说:
2023年10月22日 13:12

I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Thanks... ufabetทางเข้าเล่น

Avatar_small
GD Kitchen 说:
2023年11月15日 03:59

The kitchen is my sanctuary, where the magic of ingredients transforms into delightful dishes. It's a space where creativity and flavors collide, turning ordinary foods into extraordinary experiences.

Avatar_small
tech 说:
2023年12月09日 21:19

I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job ! UFABETกติกาแทงบอล

Avatar_small
舒緩肌肉 说:
2024年1月04日 14:46

WellSpa by Nu Skin is not your typical spa experience; it’s a holistic journey that aims to rejuvenate the body, mind, and spirit. Nestled in serene locations around the world, WellSpa offers a haven of tranquility, where cutting-edge science meets ancient relaxation techniques. Click here wellspa nuskin

Avatar_small
taxiwaltononthames 说:
2024年2月01日 13:04

Experience convenient and reliable transportation with our Taxi services in Walton on Thames. Whether you're heading to the airport or exploring the town, our dedicated team ensures a comfortable and prompt journey. Choose Taxi Walton on Thames for a seamless and stress-free travel experience.

Avatar_small
Taxiwey Bridge 说:
2024年2月04日 18:59

Discover reliable and timely transportation with Taxi in Weybridge. Our service caters to your travel needs in and around Weybridge, offering prompt and comfortable rides. Choose Taxi in Weybridge for a stress-free journey, ensuring you reach your destination with ease and satisfaction.

Avatar_small
alchemai 说:
2024年3月11日 05:07

Fashion is a form of self-expression that allows us to show the world who we are and what we stand for, without having to say a word. alchemai

Avatar_small
Arash Ekbatani 说:
2024年3月22日 19:00

I think you made some good points in Features also. Keep working, great job ! <a href="https://studioarash.com" rel="external">Wedding Photographers In Toronto</a>

Avatar_small
janifer 说:
2024年5月09日 20:43

https://kokaindrogekaufen.com/
https://ketaminkaufen.com/
https://mdmakaufen.com/
https://cannaweedzone.com/
https://cannahome.net/
https://grasherr.com/de_de/
https://strongclubmeds.com/
https://floodedpcaks.com/
https://nobupacks.com/
https://gblstores.com/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter