gpt4 book ai didi

go - Golang处理错误返回时删除重复的代码

转载 作者:行者123 更新时间:2023-12-01 22:21:03 24 4
gpt4 key购买 nike

我正在通过创建Web应用程序来学习Golang。使用Go时,我经常遇到这种情况

err = SomeFunction()

// Handling err
if err != nil {
Logging(err)
return err
}
在C或C++中,“处理错误”部分可以使用MARCO或INLINE FUNCTION删除重复的代码。有人知道如何在Golang中做到吗?

最佳答案

您可以使用
https://gitlab.com/opennota/macro
像这样定义宏
在input.go.tmpl中

func MACRO_m1(a, b int) {
a = b ^ 1
}

func main(){
m1(v1, v2)
}
在命令行上
macro input.go.tmpl output.go
将转换为
func main(){
v1 = v2 ^ 1
}

关于go - Golang处理错误返回时删除重复的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63553793/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com