分类 Golang 中的文章

Debug in container

有时候我们需要对容器内部进程进行debug,当然我们可以直接拷贝delve到容器进行命令行调试, 但是由于缺少源文件会导致无法看见调试的上下文代码,可以配置 ~/.config/dlv/config.yml 中的 substitute-path参数,不过这样就繁琐了。 在容器启动时就使用delve启动debug 1. 下载delve并以容器……

阅读全文

Go 包多版本管理

项目格式 -project -bytes_core -go.mod -pool -a.go -b.go -redis_core -etcd_core 关于不同core包,版本管理的问题,主要有以下几点需要注意 每个core包里需要有mod文件,mod文件开头需要以域名/当前包路径,例如github.com/xxx/project/bytes_core 在修改完某一个core包代码后,commit完后,单独打……

阅读全文

golang unsafe初探——根据字段计算结构体实例地址

在Go中,第一个字段的地址即为结构体地址 观察代码运行结果,理解golang对象与字段地址的偏移计算 说明:Pointer和uintptr方法可以理解为本质上都是指针,前者一般用来转化类型,后者用来计算地址 type Buffer struct { buf [1500]byte n int8 } func main() { instance := new(Buffer) { println(instance) println(instance.buf[:]) println(&instance.buf[0]) b := (*Buffer)(unsafe.Pointer(&instance.buf[0])) // 根据buf字段算出实例对象的地址……

阅读全文

golang 正则

. 匹配多行,匹配包括 re := regexp.MustCompile(`(?s)i(.*?)u`) fmt.Println(re.MatchString("i\nlove\nu")) // true // 部分使用 s 模式,下同 re := regexp.MustCompile(`i(?s:.*?)l(.*)`) // 只有第一个括号中使用了s模式 fmt.Println(re.FindString("i \nlove\n u")) // i\nlove 忽略大小写 re := regexp.MustCompile(`(?i)love`) fmt.Println(re.MatchString("i\nLOVE\nu")) // true 多行使用^ $匹配行首和行尾 re := regexp.MustCompile(`(?m)^love$`) fmt.Println(re.MatchString("i\nlove\nu")) // true……

阅读全文