golang代码笔记 -- 基础库归纳(持续更新)

这篇博客总结了Golang开发中常用的基础库,包括strconv、regexp、time、timer、bytes、fmt、io、bufio、io/ioutil、log、fmt和sync。内容涵盖数字与字符串转换、正则表达式、时间处理、缓存、格式化输出、IO操作、日志记录和并发同步等关键知识点。
摘要由CSDN通过智能技术生成

主要内容

主要根据自己在开发过程中的使用经验,总结一下常用的基础包的使用方式;

可能会有疏漏和错误,主要是强迫自己来进行总结;

参考:https://godoc.org/-/go

归纳列表

1.string & strconv

strconv – 数字转换

strconv包最常用的是整型,浮点型,布尔等类型和字符串的转换;

FormatBool  -- "true"/"false"
FormatFloat
FormatInt
FormatUint

ParseBool
ParseFloat
ParseInt
ParseUint

Itoa  -- 转字符串
Atoi --int

## 其中FormatFloat的使用细节,可以简化大部分浮点数的格式化问题
func FormatFloat(f float64, fmt byte, prec, bitSize int) string

f: 需要格式化的浮点数
fmt: 格式化表述,如下
prec: 精度(小数位数)
bitSize: 保存字节大小(64->32可能会进行四舍五入),特别的是,-1让函数自己判断需要使用的位数

fmt格式化:
'b' : -ddddp±ddd, 二进制指数
'e'/'E' : -d.dddde±dd/-d.ddddE±dd,十进制指数
'f' : -ddd.dddd,非指数
'g'/'G' : 对于大数相当于'e'/'E' ,否则和'f'一样
  • strconv – 字符串转换*

其实strconv来做字符串转换的时间很少,主要包含quote,ascii相关转换;以及将数字转换和字符串转换相结合的AppendXXX函数;

func Quote(s string) string
func QuoteRune(r rune) string
func QuoteRuneToASCII(r rune) string
func QuoteRuneToGraphic(r rune) string
func QuoteToASCII(s string) string
func QuoteToGraphic(s string) string
func Unquote(s string) (string, error)
func UnquoteChar(s string, quote byte) (value rune, multibyte bool, tail string, err error)

func AppendBool(dst []byte, b bool) []byte
func AppendFloat(dst []byte, f float64, fmt byte, prec, bitSize int) []byte
func AppendInt(dst []
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值