From 683e302fa48f613c0489094ce18c486bb231f4ce Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 3 Jul 2017 14:01:17 +0100 Subject: Added "-c" option to specify config file --- binnit.go | 14 +++++++++++--- config.go | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/binnit.go b/binnit.go index 1b11f03..0aaae5b 100644 --- a/binnit.go +++ b/binnit.go @@ -33,9 +33,14 @@ import ( "time" "io" "binnit/paste" + "flag" ) +var conf_file = flag.String("c", "./binnit.cfg", "Configuration file for binnit") + + + var p_conf = Config{ server_name: "localhost", bind_addr: "0.0.0.0", @@ -147,13 +152,15 @@ func req_handler(w http.ResponseWriter, r *http.Request) { } } + + func main() { - - parse_config("binnit.cfg", &p_conf) - + flag.Parse() + parse_config(*conf_file, &p_conf) + f, err := os.OpenFile(p_conf.log_file, os.O_APPEND | os.O_CREATE | os.O_RDWR, 0600) if err != nil { fmt.Fprintf(os.Stderr, "Error opening log_file: %s. Exiting\n", p_conf.log_file) @@ -167,6 +174,7 @@ func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds) log.Println("Binnit version 0.1 -- Starting ") + log.Printf(" + Config file: %s\n", *conf_file) log.Printf(" + Serving pastes on: %s\n", p_conf.server_name) log.Printf(" + listening on: %s:%s\n", p_conf.bind_addr, p_conf.bind_port ) log.Printf(" + paste_dir: %s\n", p_conf.paste_dir) diff --git a/config.go b/config.go index 9967ab8..aa9d966 100644 --- a/config.go +++ b/config.go @@ -34,6 +34,10 @@ import ( "strconv" ) +type Options struct { + conf_file string +} + type Config struct { server_name string -- cgit v1.2.3