go.talks/present: combine main.go and local.go
R=golang-dev, campoy
CC=golang-dev
https://golang.org/cl/7306049
diff --git a/present/local.go b/present/local.go
index 8674dfd..c800f78 100644
--- a/present/local.go
+++ b/present/local.go
@@ -7,14 +7,72 @@
package main
import (
+ "flag"
+ "fmt"
+ "go/build"
+ "log"
"net/http"
+ "os"
+ "strings"
+ "code.google.com/p/go.talks/pkg/present"
"code.google.com/p/go.talks/pkg/socket"
)
-// HandleSocket registers the websocket handler with http.DefaultServeMux under
-// the given path.
-func HandleSocket(path string) {
- playScript(basePath, "socket.js")
- http.Handle(path, socket.Handler)
+const basePkg = "code.google.com/p/go.talks/present"
+
+var basePath string
+
+func main() {
+ httpListen := flag.String("http", "127.0.0.1:3999", "host:port to listen on")
+ flag.StringVar(&basePath, "base", "", "base path for slide template and static resources")
+ flag.BoolVar(&present.PlayEnabled, "play", true, "enable playground (permit execution of arbitrary user code)")
+ flag.Parse()
+
+ if basePath == "" {
+ p, err := build.Default.Import(basePkg, "", build.FindOnly)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Couldn't find gopresent files: %v\n", err)
+ fmt.Fprintf(os.Stderr, basePathMessage, basePkg)
+ os.Exit(1)
+ }
+ basePath = p.Dir
+ }
+
+ if present.PlayEnabled {
+ playScript(basePath, "socket.js")
+ http.Handle("/socket", socket.Handler)
+ }
+ http.Handle("/static/", http.FileServer(http.Dir(basePath)))
+
+ if !strings.HasPrefix(*httpListen, "127.0.0.1") &&
+ !strings.HasPrefix(*httpListen, "localhost") &&
+ present.PlayEnabled {
+ log.Print(localhostWarning)
+ }
+
+ log.Printf("Open your web browser and visit http://%s/", *httpListen)
+ log.Fatal(http.ListenAndServe(*httpListen, nil))
}
+
+const basePathMessage = `
+By default, gopresent locates the slide template files and associated
+static content by looking for a %q package
+in your Go workspaces (GOPATH).
+
+You may use the -base flag to specify an alternate location.
+`
+
+const localhostWarning = `
+WARNING! WARNING! WARNING!
+
+The present server appears to be listening on an address that is not localhost.
+Anyone with access to this address and port will have access to this machine as
+the user running present.
+
+To avoid this message, listen on localhost or run with -play=false.
+
+If you don't understand this message, hit Control-C to terminate this process.
+
+WARNING! WARNING! WARNING!
+`
diff --git a/present/main.go b/present/main.go
deleted file mode 100644
index 9b99d2d..0000000
--- a/present/main.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2012 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// +build !appengine
-
-package main
-
-import (
- "flag"
- "fmt"
- "go/build"
- "log"
- "net/http"
- "os"
- "strings"
-
- "code.google.com/p/go.talks/pkg/present"
-)
-
-const basePkg = "code.google.com/p/go.talks/present"
-
-var basePath string
-
-func main() {
- httpListen := flag.String("http", "127.0.0.1:3999", "host:port to listen on")
- flag.StringVar(&basePath, "base", "", "base path for slide template and static resources")
- flag.BoolVar(&present.PlayEnabled, "play", true, "enable playground (permit execution of arbitrary user code)")
- flag.Parse()
-
- if basePath == "" {
- p, err := build.Default.Import(basePkg, "", build.FindOnly)
- if err != nil {
- fmt.Fprintf(os.Stderr, "Couldn't find gopresent files: %v\n", err)
- fmt.Fprintf(os.Stderr, basePathMessage, basePkg)
- os.Exit(1)
- }
- basePath = p.Dir
- }
-
- if present.PlayEnabled {
- HandleSocket("/socket")
- }
- http.Handle("/static/", http.FileServer(http.Dir(basePath)))
-
- if !strings.HasPrefix(*httpListen, "127.0.0.1") &&
- !strings.HasPrefix(*httpListen, "localhost") &&
- present.PlayEnabled {
- log.Print(localhostWarning)
- }
-
- log.Printf("Open your web browser and visit http://%s/", *httpListen)
- log.Fatal(http.ListenAndServe(*httpListen, nil))
-}
-
-const basePathMessage = `
-By default, gopresent locates the slide template files and associated
-static content by looking for a %q package
-in your Go workspaces (GOPATH).
-
-You may use the -base flag to specify an alternate location.
-`
-
-const localhostWarning = `
-WARNING! WARNING! WARNING!
-
-The present server appears to be listening on an address that is not localhost.
-Anyone with access to this address and port will have access to this machine as
-the user running present.
-
-To avoid this message, listen on localhost or run with -play=false.
-
-If you don't understand this message, hit Control-C to terminate this process.
-
-WARNING! WARNING! WARNING!
-`