From 057713b443196418f981ce982459072fdaaeabba Mon Sep 17 00:00:00 2001 From: Sai Kiran Anagani Date: Mon, 18 Sep 2017 18:50:07 +0530 Subject: [PATCH] change config file to be placed in home directory --- README.md | 2 +- digitalocean-dynamic-ip.go | 8 ++++---- config.sample.json => digitalocean-dynamic-ip.sample.json | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename config.sample.json => digitalocean-dynamic-ip.sample.json (100%) diff --git a/README.md b/README.md index 840c207..ecec89a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Requires that the record already exists in DigitalOcean's DNS. ```bash git clone https://github.com/anaganisk/digitalocean-dynamic-dns-ip.git ``` -create a file config.json and place it same directory as this script and add the following json +create a file ".digitalocean-dynamic-ip.json"(dot prefix to hide the file) and place it user home directory and add the following json ```json { diff --git a/digitalocean-dynamic-ip.go b/digitalocean-dynamic-ip.go index 3f0a030..200b2e0 100644 --- a/digitalocean-dynamic-ip.go +++ b/digitalocean-dynamic-ip.go @@ -6,8 +6,9 @@ import ( "io/ioutil" "log" "net/http" - "path/filepath" "strconv" + + homedir "github.com/mitchellh/go-homedir" ) func checkError(err error) { @@ -37,10 +38,9 @@ type DOResponse struct { } func main() { - // load config - absPath, err := filepath.Abs("./config.json") + homeDirectory, err := homedir.Dir() checkError(err) - getfile, err := ioutil.ReadFile(absPath) + getfile, err := ioutil.ReadFile(homeDirectory + "/.digitalocean-dynamic-ip.json") checkError(err) var config ClientConfig json.Unmarshal(getfile, &config) diff --git a/config.sample.json b/digitalocean-dynamic-ip.sample.json similarity index 100% rename from config.sample.json rename to digitalocean-dynamic-ip.sample.json