| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 func main() { | 49 func main() { |
| 50 var configuration = flag.String("t", "Release", "The target configuration (i
.e. Release or Debug)") | 50 var configuration = flag.String("t", "Release", "The target configuration (i
.e. Release or Debug)") |
| 51 | 51 |
| 52 flag.Parse() | 52 flag.Parse() |
| 53 flag.Usage = usage | 53 flag.Usage = usage |
| 54 // The built-in go:flag is awful. It only allows short-name arguments | 54 // The built-in go:flag is awful. It only allows short-name arguments |
| 55 // and they *must* be before any unnamed arguments. There are better ones: | 55 // and they *must* be before any unnamed arguments. There are better ones: |
| 56 // https://godoc.org/github.com/jessevdk/go-flags | 56 // https://godoc.org/github.com/jessevdk/go-flags |
| 57 // but for now we're using raw-go. | 57 // but for now we're using raw-go. |
| 58 if flag.NArg() != 2 { | 58 if flag.NArg() != 3 { |
| 59 usage() | 59 usage() |
| 60 } | 60 } |
| 61 | 61 |
| 62 root, _ := filepath.Abs(flag.Arg(0)) | 62 root, _ := filepath.Abs(flag.Arg(0)) |
| 63 port := flag.Arg(1) | 63 port := flag.Arg(1) |
| 64 packageRoot := flag.Arg(2) |
| 64 | 65 |
| 66 // genRoot should not be needed once we figure out how mojom generation |
| 67 // for sdk users should work. |
| 65 genRoot := path.Join(root, "out", *configuration, "gen") | 68 genRoot := path.Join(root, "out", *configuration, "gen") |
| 66 | 69 |
| 67 fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port) | 70 fmt.Fprintf(os.Stderr, "Mappings for localhost:%s:\n", port) |
| 68 | 71 |
| 69 fmt.Fprintf(os.Stderr, " / -> %s\n", root) | 72 fmt.Fprintf(os.Stderr, " / -> %s\n", root) |
| 70 http.Handle("/", skyHandler(root)) | 73 http.Handle("/", skyHandler(root)) |
| 71 | 74 |
| 72 fmt.Fprintf(os.Stderr, " /echo_post -> custom echo handler\n") | 75 fmt.Fprintf(os.Stderr, " /echo_post -> custom echo handler\n") |
| 73 http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) { | 76 http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) { |
| 74 defer r.Body.Close() | 77 defer r.Body.Close() |
| 75 body, _ := ioutil.ReadAll(r.Body) | 78 body, _ := ioutil.ReadAll(r.Body) |
| 76 w.Write(body) | 79 w.Write(body) |
| 77 }) | 80 }) |
| 78 | 81 |
| 79 addMapping("/gen/", genRoot) | 82 addMapping("/gen/", genRoot) |
| 83 addMapping("/packages/", packageRoot) |
| 80 | 84 |
| 81 http.ListenAndServe(":" + port, nil) | 85 http.ListenAndServe(":" + port, nil) |
| 82 } | 86 } |
| OLD | NEW |