Packaging config files

691 views
Skip to first unread message

Dump Hole

unread,
Jan 11, 2015, 3:29:11 PM1/11/15
to golan...@googlegroups.com
How would go package the config files for an app?  I have created some config files that need to be loaded at runtime, but these files are not included as part of the `go install` command, so when you are executing the app binary, these files are missing.

Luna Duclos

unread,
Jan 11, 2015, 5:26:56 PM1/11/15
to Dump Hole, golang-nuts
I tend to just package reasonable defaults into my code, which my app defaults to if lacking the default config files

On Sun, Jan 11, 2015 at 9:29 PM, Dump Hole <dumpst...@gmail.com> wrote:
How would go package the config files for an app?  I have created some config files that need to be loaded at runtime, but these files are not included as part of the `go install` command, so when you are executing the app binary, these files are missing.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dump Hole

unread,
Jan 11, 2015, 7:44:28 PM1/11/15
to golan...@googlegroups.com, dumpst...@gmail.com
Well, the problem isn't the default values, it's the fact that `go install` only packages the source code and does not include the supplemental files.  This is a small issue but petty.  I can easily copy-paste these files to go/bin folder, but I feel like this is very hackish, unless that's the recommended way of doing it.

Does go has a build file of some sort, where I can specify which files to include in the build process?

Dan Kortschak

unread,
Jan 11, 2015, 7:48:08 PM1/11/15
to Dump Hole, golan...@googlegroups.com
On Sun, 2015-01-11 at 16:44 -0800, Dump Hole wrote:
> Well, the problem isn't the default values, it's the fact that `go
> install`
> only packages the source code and does not include the supplemental
> files.
>
Why not specify a config location and check whether the config is there,
if it isn't write a default to that location?

Michael Daffin

unread,
Jan 11, 2015, 8:40:44 PM1/11/15
to Dan Kortschak, Dump Hole, golan...@googlegroups.com

This depends on what type of application you are writing.

If it is a service on Linux then the configs should go in /etc somewhere and you just leave that up to the users/packagers to do that. As suggested if your app has defaults built in then they should be used if the config dose not exist.

If it is a user land tool that has a config per user then the settings file should be written by the application in the default place for user configuration on the system ie somewhere in  %AppData% on windows and $XDG_CONFIG_HOME on linux.

Either way they really should not go in $GOPATH/bin

If you must do this in an automated way then I suggest wrapping the build commands in a Makefile that also installs the other files you need.

Dump Hole

unread,
Jan 12, 2015, 2:09:24 AM1/12/15
to golan...@googlegroups.com, dan.ko...@adelaide.edu.au, dumpst...@gmail.com
I kept forgetting that go development environment is still very similar to C.

These config files are part of the files that I would check into git, so they will naturally live in the go/src folder.  So it does look like `go install` is not enough that I would have to create a makefile for each project, and specify which files I want to include when I release my app.  I can't just 'ship' the source folder.

Dobrosław Żybort

unread,
Jan 12, 2015, 2:22:55 AM1/12/15
to golan...@googlegroups.com, dan.ko...@adelaide.edu.au, dumpst...@gmail.com
Try https://github.com/GeertJohan/go.rice it should find your config files in go/src folders.

Dan Kortschak

unread,
Jan 12, 2015, 2:27:47 AM1/12/15
to Dump Hole, golan...@googlegroups.com, dumpst...@gmail.com
Why not?

Kelsey Hightower

unread,
Jan 12, 2015, 2:38:11 AM1/12/15
to golan...@googlegroups.com
I guess the first question to ask: Are these really configuration files? Can they be changed independently of the binary? If the answer is yes and you really want to read them from a file system why not stick them under /etc/${app}.conf?

IMO if you plan to bake the configs in the binary, then just store values in a config package:

package config

var (
    Config1 = "value"
    Config2 = "value"
)

But doing this seems odd. I think a better option is to start by deploying the config files using the same mechanism used to distribute the binary.

DH

unread,
Jan 12, 2015, 3:38:48 AM1/12/15
to Dobrosław Żybort, golan...@googlegroups.com, dan.ko...@adelaide.edu.au
Thanks! I will give this a try.  This looks like something I am looking for.
Reply all
Reply to author
Forward
0 new messages