func (cmd *serverCommand) generateIndexHTML() (string, error) {
	var files string
	walkPastes := func(pth string, f os.FileInfo, err error) error {
		base := filepath.Base(pth)
		if base != cmd.storage {
			files += fmt.Sprintf(`<tr>
<td><a href="%s%s">%s</a></td>
<td>%s</td>
<td>%d</td>
</tr>`, baseuri, base, base, f.ModTime().Format("2006-01-02T15:04:05Z07:00"), f.Size())
		}
		return nil
	}
	if err := filepath.Walk(cmd.storage, walkPastes); err != nil {
		return "", fmt.Errorf("walking %s failed: %v", cmd.storage, err)
	}
	html := fmt.Sprintf(`%s
<table>
	<thead>
		<tr>
			<th>name</th><th>modified</th><th>size</th>
		</tr>
	</thead>
	<tbody>
		%s
	</tbody>
</table>
%s`, htmlBegin, files, htmlEnd)
	return html, nil
}
generateIndexHTML generates the html for the index page
to list all the pastes, via walking the storage directory.
package main
import (
	"context"
	"crypto/rand"
	"encoding/json"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"os"
	"path"
	"path/filepath"
	"strings"
	"github.com/buildkite/terminal"
	"github.com/sirupsen/logrus"
	"github.com/sourcegraph/syntaxhighlight"
)
const (
	htmlBegin string = `<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" href="/static/favicon.ico" />
<link rel="stylesheet" media="all" href="/static/main.css"/>
<link rel="stylesheet" media="all" href="/static/ansi.css"/>
</head>
<body>`
	htmlEnd string = `</body>
</html>`
	serverHelp = `Run the server.`
)
func (cmd *serverCommand) Name() string      { return "server" }
func (cmd *serverCommand) Args() string      { return "[OPTIONS]" }
func (cmd *serverCommand) ShortHelp() string { return serverHelp }
func (cmd *serverCommand) LongHelp() string  { return serverHelp }
func (cmd *serverCommand) Hidden() bool      { return false }
func (cmd *serverCommand) Register(fs *flag.FlagSet) {
	fs.StringVar(&cmd.cert, "cert", "", "path to ssl cert")
	fs.StringVar(&cmd.key, "key", "", "path to ssl key")
	fs.StringVar(&cmd.port, "port", "8080", "port for server to run on")
	fs.StringVar(&cmd.storage, "s", "/etc/pastebinit/files", "directory to store pastes")
	fs.StringVar(&cmd.storage, "storage", "/etc/pastebinit/files", "directory to store pastes")
	fs.StringVar(&cmd.assetPath, "asset-path", "/src/static", "Path to assets and templates")
}
type serverCommand struct {
	cert string
	key  string
	port string
	storage   string
	assetPath string
}
type JSONResponse map[string]string
func (j JSONResponse) String() string {
	str, err := json.MarshalIndent(j, "", "  ")
	if err != nil {
		return fmt.Sprintf(`{
  "error": "%v"
}`, err)
	}
	return string(str)
}
func (cmd *serverCommand) Run(ctx context.Context, args []string) error {
	if err := os.MkdirAll(cmd.storage, 0755); err != nil {
		logrus.Fatalf("creating storage directory %q failed: %v", cmd.storage, err)
	}
	mux := http.NewServeMux()
	staticHandler := http.StripPrefix("/static/", http.FileServer(http.Dir(cmd.assetPath)))
	mux.Handle("/static/", staticHandler)
	mux.HandleFunc("/paste", cmd.pasteUploadHandler)  
	mux.HandleFunc("/", cmd.pasteHandler)             
	server := &http.Server{
		Addr:    ":" + cmd.port,
		Handler: mux,
	}
	logrus.Infof("Starting server on port %s", cmd.port)
	if len(cmd.cert) > 0 && len(cmd.key) > 0 {
		return server.ListenAndServeTLS(cmd.cert, cmd.key)
	}
	return server.ListenAndServe()
}