Created
May 19, 2020 22:47
-
-
Save shinchit/dd5d71851b1024e2420dc4a875e1f196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
import ( | |
"log" | |
"os" | |
"gopkg.in/ini.v1" | |
) | |
type configList struct { | |
APIKey string | |
APISecret string | |
LogFile string | |
DefaultRunMode string | |
} | |
// Config is Implementation of ConfigList | |
var Config configList | |
func init() { | |
cfg, err := ini.Load("config.ini") | |
if err != nil { | |
log.Printf("Failed to read file: %v", err) | |
os.Exit(1) | |
} | |
Config = configList{ | |
APIKey: cfg.Section("api").Key("api_key").String(), | |
APISecret: cfg.Section("api").Key("api_secret").String(), | |
LogFile: cfg.Section("app").Key("log_file").String(), | |
ProductCode: cfg.Section("app").Key("default_run_mode").String(), | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"sample/config" | |
) | |
func main() { | |
// print config.ini values | |
fmt.Println("APIKey: ", config.Config.APIKey) | |
fmt.Println("APISecret: ", config.Config.APISecret) | |
fmt.Println("LogFile: ", config.Config.LogFile) | |
fmt.Println("DefaultRunMode: ", config.Config.DefaultRunMode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment