From cd95aa3dc71bec3d15541424f328b6f3735432f1 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 3 Jul 2017 10:40:48 +0100 Subject: config options reorganised. More robust config parser. --- main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 76bc4a0..6c3c151 100644 --- a/main.go +++ b/main.go @@ -14,8 +14,9 @@ import ( var p_conf = Config{ - host: "localhost", - port: "8000", + server_name: "localhost", + bind_addr: "0.0.0.0", + bind_port: "8000", paste_dir: "./pastes", templ_dir: "./tmpl", log_fname: "./binit.log", @@ -108,13 +109,14 @@ func handle_put_paste(w http.ResponseWriter, r *http.Request) { if err := ioutil.WriteFile(paste_dir+ paste_name, []byte(content), 0644); err == nil { // and then we return the URL: log.Printf(" `-- saving paste to : %s", paste_dir + paste_name) - hostname := r.Host + //hostname := r.Host + hostname := p_conf.server_name if show := req_body.Get("show"); show != "1" { fmt.Fprintf(w, "%s/%s", hostname, paste_name) return } else{ - fmt.Fprintf(w, "Link: %s", - paste_hash[i:i+16], paste_hash[i:i+16]) + fmt.Fprintf(w, "Link: http://%s/%s", + hostname, paste_hash[i:i+16], hostname, paste_hash[i:i+16]) return } } else { @@ -158,12 +160,13 @@ func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds) log.Println("Binit version 0.1 -- Starting ") - log.Printf(" + listening on: %s:%s\n", p_conf.host, p_conf.port ) + 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) log.Printf(" + templ_dir: %s\n", p_conf.templ_dir) log.Printf(" + max_size: %d\n", p_conf.max_size) http.HandleFunc("/", req_handler) - log.Fatal(http.ListenAndServe(p_conf.host + ":" + p_conf.port, nil)) + log.Fatal(http.ListenAndServe(p_conf.bind_addr + ":" + p_conf.bind_port, nil)) } -- cgit v1.2.3