Skip to content

Instantly share code, notes, and snippets.

@shinchit
Created May 19, 2020
Embed
What would you like to do?
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(),
}
}
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