| Index: sky/tools/skygo/sky_server.go
|
| diff --git a/sky/tools/skygo/sky_server.go b/sky/tools/skygo/sky_server.go
|
| index e851487c09d4ab0fb9b0670031f299077ad5349e..a7117ce248d52cf7d3bd76f5c75521d9bef157fe 100644
|
| --- a/sky/tools/skygo/sky_server.go
|
| +++ b/sky/tools/skygo/sky_server.go
|
| @@ -6,9 +6,12 @@ package main
|
|
|
| import (
|
| "flag"
|
| + "fmt"
|
| "io/ioutil"
|
| "net/http"
|
| + "os"
|
| "path"
|
| + "path/filepath"
|
| "strings"
|
| )
|
|
|
| @@ -28,25 +31,54 @@ func (handler *skyHandlerRoot) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
| http.ServeFile(w, r, path)
|
| }
|
|
|
| +func usage() {
|
| + fmt.Fprintf(os.Stderr, "Usage: sky_server [flags] MOJO_SRC_ROOT PORT\n\n")
|
| + fmt.Fprintf(os.Stderr, "launches a basic http server with mappings into the\n")
|
| + fmt.Fprintf(os.Stderr, "mojo repository for framework/service paths.\n")
|
| + fmt.Fprintf(os.Stderr, "[flags] MUST be before arguments, because go:flag.\n\n")
|
| + flag.PrintDefaults()
|
| + os.Exit(2)
|
| +}
|
| +
|
| +func addMapping(from_path string, to_path string) {
|
| + // Print to stderr to it's more obvious what this binary does.
|
| + fmt.Fprintf(os.Stderr, " %s -> %s\n", from_path, to_path)
|
| + http.Handle(from_path, http.StripPrefix(from_path, skyHandler(to_path)))
|
| +}
|
| +
|
| func main() {
|
| var configuration = flag.String("t", "Release", "The target configuration (i.e. Release or Debug)")
|
| +
|
| flag.Parse()
|
| + flag.Usage = usage
|
| + // The built-in go:flag is awful. It only allows short-name arguments
|
| + // and they *must* be before any unnamed arguments. There are better ones:
|
| + // https://godoc.org/github.com/jessevdk/go-flags
|
| + // but for now we're using raw-go.
|
| + if flag.NArg() != 2 {
|
| + usage()
|
| + }
|
|
|
| - args := flag.Args()
|
| - root := args[0]
|
| - port := args[1]
|
| + root, _ := filepath.Abs(flag.Arg(0))
|
| + port := flag.Arg(1)
|
|
|
| genRoot := path.Join(root, "out", *configuration, "gen")
|
|
|
| + fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port)
|
| +
|
| + fmt.Fprintf(os.Stderr, " / -> %s\n", root)
|
| http.Handle("/", skyHandler(root))
|
| +
|
| + fmt.Fprintf(os.Stderr, " /echo_post -> custom echo handler\n")
|
| http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) {
|
| defer r.Body.Close()
|
| body, _ := ioutil.ReadAll(r.Body)
|
| w.Write(body)
|
| })
|
| - http.Handle("/mojo/public/", http.StripPrefix("/mojo/public/", skyHandler(path.Join(genRoot, "mojo", "public"))))
|
| - http.Handle("/mojo/services/", http.StripPrefix("/mojo/services/", skyHandler(path.Join(genRoot, "mojo", "services"))))
|
| - http.Handle("/sky/services/", http.StripPrefix("/sky/services/", skyHandler(path.Join(genRoot, "sky", "services"))))
|
| +
|
| + addMapping("/mojo/public/", path.Join(genRoot, "mojo", "public"))
|
| + addMapping("/mojo/services/", path.Join(genRoot, "mojo", "services"))
|
| + addMapping("/sky/services/", path.Join(genRoot, "sky", "services"))
|
|
|
| http.ListenAndServe(":" + port, nil)
|
| }
|
|
|