Go wrapper script: get Hugo config?

Hi there, I’m using a Go wrapper script to pull in some external data and process it before building my site with Hugo, as well as for some linting, a deploy option etc.

For calling hugo server and hugo deploy from Go, I’m using the Execute function from github.com/gohugoio/hugo/commands, that works great.

But now, I’d like to read in some config values. I could call hugo config with the same Execute function, but the problem is that Execute only returns an error (or nil), and the output, which I need, ends up in the standard output.

My questions are as follows:

  1. Is using the Execute function the recommended way to get the config, or should I use github.com/gohugoio/hugo/config/allconfig somehow?
  2. If Execute is the way to go, how do I get the output? Could you perhaps add an io.Writer or similar as argument to Execute, that Hugo can write its output to?

Thank you and best, Ruben

For future reference, I’ve “solved” this by capturing the standard output and then using the FromConfigString() function from "github.com/gohugoio/hugo/config" to parse that configuration.
Relevant files:

Hope this helps anyone trying to solve the same issue :smile: