github.com/agrison/harpoon@v0.0.0-20180819075247-a667a15fd0eb/config.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/BurntSushi/toml"
     7  )
     8  
     9  type tomlConfig struct {
    10  	Port       int    `toml:"port"`
    11  	Addr       string `toml:"addr"`
    12  	Events     map[string]event
    13  	Tunnel     bool
    14  	TunnelName string
    15  }
    16  
    17  type event struct {
    18  	Cmd  string `toml:"cmd"`
    19  	Args string `toml:"args"`
    20  }
    21  
    22  // loadConfig loads the config.toml file into a tomlConfig struct
    23  func loadConfig() tomlConfig {
    24  	var config tomlConfig
    25  	if configFile != "" {
    26  		if _, err := toml.DecodeFile(configFile, &config); err != nil {
    27  			fmt.Println(err)
    28  			fmt.Println("failed loading config, going to fallback")
    29  		} else {
    30  			return config
    31  		}
    32  	}
    33  	if _, err := toml.DecodeFile("./config.toml", &config); err != nil {
    34  		fmt.Println(err)
    35  		panic("nope")
    36  	}
    37  	return config
    38  }