dplece1882 2017-12-09 18:43
浏览 63

yaml.v2 Unmarshaller接口的状态实现?

This could either be a file path question, or a question on how to best implement an interface.

Given the following very simple yaml:

name: MyYamlName
data: some/relative/path.txt

I would like to unmarshal it to the following struct:

type VerySimple struct {
    name string
    data io.Reader
}

I'm already using the yaml.v2 library, and know that for simple types, I can implement the Unmarshaller interface. However, in my program, I can't assume an absolute root from which to base the relative path in the data field.

Is there a way to implement the Unmarshaller interface to pass a working directory, or maybe a different way to handle relative paths in Go?

  • 写回答

1条回答 默认 最新

  • doutonghang2761 2017-12-09 19:10
    关注

    It's pretty clear from the API documentation that this isn't supported. The natural way to support it, IMO, would be with a Decoder type, analogous to the json.Decoder type. It could be initialized with a root include path, or a list of include paths to search.

    There is already a request for such a feature. It does mention working with multiple documents, which probably implies including an include path, although that specific feature has not yet been explicitly mentioned. I suggest offering your ideas in that thread.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用