0

I'm writing a go application that writes values to a file.

However, I want the location of that file to be determined at runtime (i.e. not set as part of the application code).

I have create a test client for the application and I want the client to tell the application which file it should write to.

Can anyone tell me how I would go about this in Go?

Thanks,

Sean

Seán
  • 523
  • 2
  • 10
  • 17

1 Answers1

1

If the location is not set, you'll need to read it in some way.

  • You might want to read it from a command line flag passed in when running the command. The easiest way to do that is using the flag package.
  • You could read it from STDIN. The top answer to this question nicely explains how to do that.
  • You could read it from an environment variable. Check out the Environ function in the os package.
Community
  • 1
  • 1
bigblind
  • 12,539
  • 14
  • 68
  • 123
  • To add, you can also read it from the client as well. Just have the application expect it from a connection. – Anfernee Mar 22 '16 at 23:00