提交 8eb95faf 作者: verokarhu

moved http to server/http and implemented serve http subcommand

上级 0a25b64f
...@@ -43,7 +43,7 @@ Tool commands: ...@@ -43,7 +43,7 @@ Tool commands:
Advanced Commands: Advanced Commands:
mount Mount an ipfs read-only mountpoint. mount Mount an ipfs read-only mountpoint.
serve Serve an http gateway into ipfs. serve Serve an interface to ipfs.
Use "ipfs help <command>" for more information about a command. Use "ipfs help <command>" for more information about a command.
``` ```
......
...@@ -35,7 +35,7 @@ Tool commands: ...@@ -35,7 +35,7 @@ Tool commands:
Advanced Commands: Advanced Commands:
mount Mount an ipfs read-only mountpoint. mount Mount an ipfs read-only mountpoint.
serve Serve an http gateway into ipfs. serve Serve an interface to ipfs.
Use "ipfs help <command>" for more information about a command. Use "ipfs help <command>" for more information about a command.
`, `,
......
...@@ -5,23 +5,32 @@ import ( ...@@ -5,23 +5,32 @@ import (
"fmt" "fmt"
"github.com/gonuts/flag" "github.com/gonuts/flag"
"github.com/jbenet/commander" "github.com/jbenet/commander"
h "github.com/jbenet/go-ipfs/http" h "github.com/jbenet/go-ipfs/server/http"
) )
var cmdIpfsServe = &commander.Command{ var cmdIpfsServe = &commander.Command{
UsageLine: "serve", UsageLine: "serve",
Short: "Serve an interface to ipfs",
Subcommands: []*commander.Command{
cmdIpfsServeHttp,
},
Flag: *flag.NewFlagSet("ipfs-serve", flag.ExitOnError),
}
var cmdIpfsServeHttp = &commander.Command{
UsageLine: "http",
Short: "Serve an HTTP API", Short: "Serve an HTTP API",
Long: `ipfs serve - Serve an http gateway into ipfs.`, Long: `ipfs serve http - Serve an http gateway into ipfs.`,
Run: serveCmd, Run: serveHttpCmd,
Flag: *flag.NewFlagSet("ipfs-serve", flag.ExitOnError), Flag: *flag.NewFlagSet("ipfs-serve-http", flag.ExitOnError),
} }
func init() { func init() {
cmdIpfsServe.Flag.Uint("port", 8080, "Port number") cmdIpfsServeHttp.Flag.Uint("port", 8080, "Port number")
cmdIpfsServe.Flag.String("hostname", "localhost", "Hostname") cmdIpfsServeHttp.Flag.String("hostname", "localhost", "Hostname")
} }
func serveCmd(c *commander.Command, _ []string) error { func serveHttpCmd(c *commander.Command, _ []string) error {
port := c.Flag.Lookup("port").Value.Get().(uint) port := c.Flag.Lookup("port").Value.Get().(uint)
if port < 1 || port > 65535 { if port < 1 || port > 65535 {
return errors.New("invalid port number") return errors.New("invalid port number")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论