How do I pass an array of configurations to a YAML file in Golang? - go

I am trying to create a YAML configuration file using gosexy/yaml.
I know how to create a YAML file of the following format:
another:
tree:
- 1
I use the code settings.Set("another","tree",[]int{1}) to create the above file.
Now, how can I create a file of the format
another:
- tree: 1
I tried using the code settings.Set("another",[]{yaml.Set("tree",1)}) to create the above file. As it might be obvious, I receive a type error since I am not passing the type to the array.
Am I on the right track? If yes, what should be the type to be passed. If no, what is the alternative way to do this?

the type of tree that you need is []map[string]int
example code:
settings := yaml.New()
settings.Set("another", []map[string]int{{"tree": 1}})
settings.Write("test.yaml")
the result of test.yaml
another:
- tree: 1
hope it help

Related

How to declare and use map var in yaml file?

I try to write a map in y yaml file and want to use it in yaml file itself with a key. for example ->
in my yaml file I wrote -
pod_env_map:
pod1: "env1"
pod2: "env2"
pod3: "env3"
and in this yaml file itself I'm getting a var $pod_name.
So now i want to write stages with some command for all pod and correspond env.
So instead of putting multiple checks of $pod_name == 'pod1'....
I want to use above dict somehow in code like pod_env_map[$pod_name], please help me to know what should be the syntax for this? I tried to find but didn't get relavent info anywhere.

Is there a way to find duplicate key and value in YAML files?

I have a Yaml file like below:
opt:
opt-name:
- tag: 12648
opt-name-new:
- tag: 5013647
opt-name:
- tag: 12648
I want to delete opt-name as well respective tag name and value as well so that file become unique.
Can some body help me on this?

Create a dynamic path inside a yaml file

I have a yml file that contains a path for data source. Something like this:
data_source: s3://bucket/file.csv
I want to change the job to grab only the file with yesterday appended to the title, for example:
file-2021-10-21.csv
so basically, something like this:
data_source: s3://bucket/file-{yesterday}.csv
How can i define it in the yaml file? thanks!
You can have something like below, where all files defined under 'files' variable
data_source: s3://bucket/file-
files:
- 2021-10-21.csv
- 2021-10-21.csv

How to use lookup tables as .tx in Rasa?

In my nlu.yml file I have my code as:
- lookup: project
project.txt
My project.txt file in in under data and so is my nlu.yml file.
I'm getting the exception as yaml syntax exception, could not find expectated ':'
Could someone help me out? Where should I put that colon?
You should convert project.txt to yml format.
This answer should help you.

Issue with file sink and filename expression

Trying to set up simple file copy processin spring-xd:
stream create --name mystrea --definition "file --dir=/path/source
--fixedDelay=5 | sink:file --dir=/path/dest --binary=true
--name=headers['file_name']"
This seems to create and append fils to the file header['file_name'].out in the dest folder
Looking at sink:file definition
<file:outbound-channel-adapter id="files"
mode="${mode}"
charset="${charset}"
directory="${dir}"
filename-generator-expression="'${name}' + '${extensionWithDot}'"/>
I see it puts '' around the name which causes it not to be evaluated.
Any suggestions besides create new sink:simplefile module that would do what I am looking for ? Am I missing something
Yes, the standard sink is not designed to do what you are trying to do (pass in an expression for the filename).
We should add an alternative property --fileNameExpression=... or similar.
In the meantime, you are correct, you'll need a custom sink (or modify the standard one).
I created a JIRA Issue for this enhancement.

Resources