blob: 326d6f48e8bae08f90bc2f7d74dd52cd1d022551 [file] [log] [blame]
// Copyright 2013 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 (
const basePkg = ""
var basePath string
func main() {
httpListen := flag.String("http", "", "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)")
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)
basePath = p.Dir
if present.PlayEnabled {
playScript(basePath, "SocketTransport")
http.Handle("/socket", socket.Handler)
http.Handle("/static/", http.FileServer(http.Dir(basePath)))
if !strings.HasPrefix(*httpListen, "") &&
!strings.HasPrefix(*httpListen, "localhost") &&
present.PlayEnabled {
log.Printf("Open your web browser and visit http://%s/", *httpListen)
log.Fatal(http.ListenAndServe(*httpListen, nil))
func playable(c present.Code) bool {
return present.PlayEnabled && c.Play
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 = `
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.