From bb924cab5bd87a104bf24f73c3692cd8c6b37766 Mon Sep 17 00:00:00 2001 From: verokarhu Date: Wed, 6 Aug 2014 18:19:09 +0300 Subject: [PATCH] add port flag to serve --- cmd/ipfs/serve.go | 12 +++++++++++- http/http.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/ipfs/serve.go b/cmd/ipfs/serve.go index 367ec6e71..fe094ffae 100644 --- a/cmd/ipfs/serve.go +++ b/cmd/ipfs/serve.go @@ -1,6 +1,7 @@ package main import ( + "errors" "github.com/gonuts/flag" "github.com/jbenet/commander" h "github.com/jbenet/go-ipfs/http" @@ -14,11 +15,20 @@ var cmdIpfsServe = &commander.Command{ Flag: *flag.NewFlagSet("ipfs-serve", flag.ExitOnError), } +func init() { + cmdIpfsServe.Flag.Uint("port", 80, "Port number") +} + func serveCmd(c *commander.Command, _ []string) error { + port := c.Flag.Lookup("port").Value.Get().(uint) + if port < 1 || port > 65535 { + return errors.New("invalid port number") + } + n, err := localNode() if err != nil { return err } - return h.Serve("127.0.0.1", 80, n) + return h.Serve("127.0.0.1", port, n) } diff --git a/http/http.go b/http/http.go index 9d10c4673..5a235cb0c 100644 --- a/http/http.go +++ b/http/http.go @@ -24,7 +24,7 @@ func (i *ipfsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "%s", nd.Data) } -func Serve(host string, port uint16, node *core.IpfsNode) error { +func Serve(host string, port uint, node *core.IpfsNode) error { r := mux.NewRouter() r.PathPrefix("/").Handler(&ipfsHandler{node}).Methods("GET") http.Handle("/", r)