From f2a2b0d0a918374e7863599ae2f1f9addcc7c267 Mon Sep 17 00:00:00 2001 From: Jun Nishimura Date: Sat, 15 Jul 2023 23:11:05 +0900 Subject: [PATCH] add env.go (#10) --- env.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 env.go diff --git a/env.go b/env.go new file mode 100644 index 0000000..33c80dc --- /dev/null +++ b/env.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + + "github.com/spf13/viper" +) + +const ( + configPath = "$HOME/.config/chatify" +) + +func setEnv() { + // token setting + viper.AddConfigPath(configPath) + viper.SetConfigName("token") + viper.SetConfigType("json") + + // client setting + viper.SetConfigName("client") + viper.SetConfigType("yaml") + viper.MergeInConfig() + + // load + if err := viper.ReadInConfig(); err != nil { + if _, ok := err.(viper.ConfigFileNotFoundError); ok { + fmt.Println("config file does not exist") + } + } +}