Example #1
0
import (
	"fmt"
	"github.com/gokyle/webshell"
	"github.com/russross/blackfriday"
	"html/template"
	"io/ioutil"
	"net/http"
	"os"
	"path/filepath"
	"regexp"
)

var (
	server_port   = "8080"
	page_tpl      = webshell.MustCompileTemplate("templates/page.html")
	htmlToMd      = regexp.MustCompile("^(.+)\\.html$")
	extRegex      = regexp.MustCompile("^(.+)\\.(\\w+)$")
	slash_replace = regexp.MustCompile("/")
)

type Page struct {
	HomeActive  bool
	AboutActive bool
	Title       string
	Body        template.HTML
}

func init() {
	port := os.Getenv("PORT")
	if port != "" {
Example #2
0
	"mime/multipart"
	"net/http"
	"os"
)

type Page struct {
	Processed bool
	Image     *FormData
}

type FormData struct {
	Caption   string
	ImageFile string
}

var home_template = webshell.MustCompileTemplate("templates/index.html")

func main() {
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	app := webshell.NewApp("multipart form example", "127.0.0.1", port)
	app.AddRoute("/", home)
	app.StaticRoute("/images/", "images/")
	app.Serve()
}

func home(w http.ResponseWriter, r *http.Request) {
	if r.Method == "POST" {
		getForm(w, r)