Create a gist now

Instantly share code, notes, and snippets.

@rakyll /main.go Secret
Last active Dec 14, 2017

What would you like to do?
package main
import (
const mainJS = `console.log("hello world");`
const indexHTML = `<html>
<script src="/main.js"></script>
func main() {
http.HandleFunc("/main.js", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, mainJS)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
pusher, ok := w.(http.Pusher)
if ok { // Push is supported. Try pushing rather than waiting for the browser.
if err := pusher.Push("/main.js", nil); err != nil {
log.Printf("Failed to push: %v", err)
fmt.Fprintf(w, indexHTML)
// Run crypto/tls/generate_cert.go to generate cert.pem and key.pem.
// See
log.Fatal(http.ListenAndServeTLS(":7072", "cert.pem", "key.pem", nil))

HyeJong commented Nov 30, 2016

Thanks a lot!

vsouza commented Dec 13, 2016



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment