From 3e9875a54e2c64888b50af810e100e7bb457c503 Mon Sep 17 00:00:00 2001 From: Matt Harwood Date: Thu, 3 Sep 2020 10:43:15 +0100 Subject: [PATCH] Added config --- helpers.go | 11 +++++++++++ metafields.go | 1 + 2 files changed, 12 insertions(+) diff --git a/helpers.go b/helpers.go index 84c7076..f72dbdd 100644 --- a/helpers.go +++ b/helpers.go @@ -10,6 +10,17 @@ import ( "github.com/spf13/viper" ) +func SetConfig() { + viper.SetConfigName("config") // name of config file (without extension) + viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name + viper.AddConfigPath(".") // path to look for the config file in + err := viper.ReadInConfig() // Find and read the config file + if err != nil { // Handle errors reading the config file + panic(fmt.Errorf("Fatal error config file: %s \n", err)) + } + +} + func urltpl() string { return "https://" + viper.GetString("api-key") + ":" + viper.GetString("pass") + "@" + viper.GetString("api-url") } diff --git a/metafields.go b/metafields.go index 38de7f7..4310207 100644 --- a/metafields.go +++ b/metafields.go @@ -29,6 +29,7 @@ func GetProductMetafield(handle, mfnamspace, mfkey string) { } func SetProductMetafield(handle, namespace, key, value, valuetype string) { + SetConfig() url := urltpl() + "products/" + handle + "/metafields.json" body := ` {