diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -26,6 +26,7 @@ const ( type Server struct { data string + host string } type Metadata struct { @@ -153,7 +154,7 @@ func (s *Server) formPost(w http.ResponseWriter, r *http.Request) { return } log.Printf("Created posting: %s", name) - w.Header().Add("location", fmt.Sprintf("/%s\n", name)) + w.Header().Add("location", fmt.Sprintf("%s/%s\n", s.host, name)) w.WriteHeader(http.StatusFound) } @@ -219,7 +220,7 @@ func (s *Server) indexPost(w http.ResponseWriter, r *http.Request) { } log.Printf("Created posting: %s", name) w.WriteHeader(http.StatusCreated) - fmt.Fprintf(w, "/%s\n", name) + fmt.Fprintf(w, "%s/%s\n", s.host, name) } func (s *Server) indexGet(w http.ResponseWriter, r *http.Request) { @@ -257,9 +258,11 @@ func main() { var ( addr string data string + host string ) flag.StringVarP(&addr, "addr", "a", "0.0.0.0:9000", "The address to bind to") flag.StringVarP(&data, "data-path", "d", "./data", "The path to the data") + flag.StringVarP(&host, "host", "h", "", "The host url, e.g. http://127.0.0.1") flag.Parse() datadir, err := filepath.Abs(data) @@ -268,6 +271,7 @@ func main() { } s := &Server{ data: datadir, + host: host, } mux := http.NewServeMux() mux.HandleFunc("/post", s.Post) |
