Skip to content

Commit

Permalink
add config file support
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantmonkey committed Oct 9, 2015
1 parent cc71d28 commit b268bc9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion linx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"strconv"
"strings"

"github.com/adrg/xdg"
"golang.org/x/net/proxy"
"gopkg.in/yaml.v2"
)

type Config struct {
Expand Down Expand Up @@ -178,21 +180,38 @@ func main() {
var deleteKey string
var deleteMode bool
var ttl int
var configPath string

defaultConfigPath, err := xdg.ConfigFile("golinx/config.yml")
if err != nil {
fmt.Printf("Unable get XDG config file path: %v", err)
defaultConfigPath = ""
}

flag.StringVar(&deleteKey, "deletekey", "",
"The delete key to use for uploading or deleting a file")
flag.BoolVar(&deleteMode, "d", false,
"Delete the specified files instead of uploading")
flag.IntVar(&ttl, "ttl", 0,
"Time to live; the length of time in seconds before the file expires")
flag.StringVar(&config.Server, "server", "http://127.0.0.1:8080/",
flag.StringVar(&configPath, "config", defaultConfigPath,
"The path to the config file")
flag.StringVar(&config.Server, "server", "",
"URL to a linx server")
flag.StringVar(&config.Proxy, "proxy", "",
"URL of proxy used to access the server")
flag.StringVar(&config.UploadLog, "uploadlog", "",
"Path to the upload log file")
flag.Parse()

if configPath != "" {
data, err := ioutil.ReadFile(configPath)
if err != nil {
log.Fatal("Unable to read config file: ", err)
}
yaml.Unmarshal(data, &config)
}

if lastChar := config.Server[len(config.Server)-1:]; lastChar != "/" {
config.Server = config.Server + "/"
}
Expand Down

0 comments on commit b268bc9

Please sign in to comment.