Skip to content

Instantly share code, notes, and snippets.

@gtaylor gtaylor/gist:6378871
Created Aug 29, 2013

Embed
What would you like to do?
A very naive HTTP server that listens for a Github webhook. Upon receiving a request, we build the Pelican content and upload to S3.
/*
A very basic HTTP server that listens for Github webhooks. When we hear from
Github, build the blog and upload to S3.
Note: This is a very naive server. We don't attempt to authenticate in any
way, and we don't block to prevent spamming.
*/
package main
import (
"fmt"
"net/http"
"os/exec"
"log"
"strings"
)
func build_blog() {
log.Printf("Starting blog build...")
git_out, git_err := exec.Command("git", "pull").Output()
if git_err != nil {
log.Printf("Git: %v", git_err)
return
} else {
bar_str := strings.Repeat("G", 80)
log.Printf("\r\n%s\n\r%s", bar_str, git_out)
}
out, err := exec.Command("make", "s3_upload").Output()
if err != nil {
log.Printf("Build error: %v", err)
} else {
bar_str := strings.Repeat("P", 80)
log.Printf("\r\n%s\n\r%s%s", bar_str, out, bar_str)
}
}
func handler(w http.ResponseWriter, r *http.Request) {
go build_blog()
fmt.Fprintf(w, "OK")
}
func main() {
http.HandleFunc("/build-blog/", handler)
log.Printf("Listening...")
http.ListenAndServe(":8080", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.