dongqing344716 2016-06-12 22:29
浏览 197
已采纳

我如何输出在Docker-Compose.yml的Yaml解组中抛出错误的行?

I'm writing some code that takes in a Docker-Compose.yml and unmarshals it into a struct. I take the docker compose data in as a []byte.

    dockerData []byte
    var struct *struct
    if err := yaml.Unmarshal(dockerData, &struct)

I run a lot of compose files through this process. When errors are thrown, is there a way to output the line or section of the compose file that threw the error?

  • 写回答

1条回答 默认 最新

  • dsf23223 2016-06-15 03:16
    关注

    Set flag on the logger to print out the line number

    // main.go or config file
    
    func init() {
        log.SetFlags(log.LstdFlags | log.Lshortfile)
    }
    

    You can find more of these flags here

    handle the error

    dockerData []byte
    var struct *struct
    if err := yaml.Unmarshal(dockerData, &struct); err != nil {
        log.Print(err)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序