gpt4 book ai didi

go - YAML 修改别名序列元素

转载 作者:数据小太阳 更新时间:2023-10-29 03:22:27 25 4
gpt4 key购买 nike

我正在研究程序的配置文件格式,我想知道是否可以修改别名中定义的序列的特定元素。

例如,

# Example multi-model device configuration.
---
aliases:
- &cisco_default
vendor: cisco
cmds:
- terminal length 0 # keep
- show version | include Model number # keep
- show boot | include BOOT path-list # change this one below
- "dir flash: | include bin$" # and this one
- quit # keep

config:
- *cisco_default
- <<: *cisco_default
models:
- c4500
- c3650
cmds:
- show boot | include BOOT variable
- "dir bootflash: | include bin$"

我正在使用 Go 处理 YAML 并将其解码为一个结构。因此,如果普通 YAML 无法实现这种行为,是否有一种简单的方法可以使用 Go 的文本模板或类似的东西来修改 cmds 序列?此外,我需要保留命令的顺序。

最佳答案

通过为 cmds 设置别名得到了解决方案。这是一个允许按顺序循环命令的工作配置:

---
aliases:
- &cisco_default
vendor: cisco
cmds: &cisco_cmds
0: terminal length 0
1: show version | include Model number
2: show boot | include BOOT path-list
3: "dir flash: | include bin$"
4: quit

config:
# Default Cisco configuration.
- *cisco_default

# Cisco 4500 and 3650 model configuration.
- <<: *cisco_default
models:
- c4500
- c3650
cmds:
<<: *cisco_cmds
2: show boot | include BOOT variable
3: "dir bootflash: | include bin$"

关于go - YAML 修改别名序列元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51433037/

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