Accessing Nested Config with Viper

A Slice of Structs

Let’s start with the configured colours to send to my LED shelf (which I realised I didn’t blog about, but I should!) In the config.yaml file it is a series of objects, with properties red, green and blue:

shelf_lights:
- red: 120
blue: 200
- red: 120
green: 150
- blue: 200
green: 40
red: 60

Map of Structs with String Keys

This is pretty similar to above but I think a specific example might help. With a section of the yaml config file like this:

obs_scenes:
Camera:
name: Camera
image: "/camera.png"
Offline:
name: Offline
image: "/offline.png"
Secrets:
name: Secrets
image: "/secrets.png"

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Lorna Mitchell

Lorna Mitchell

Polyglot programmer, technology addict, open source fanatic and incurable blogger (see http://lornajane.net)