Created
December 31, 2013 02:49
-
-
Save phred/8191758 to your computer and use it in GitHub Desktop.
Stupid little webserver for controlling my Raspberry Pi cheerlights/lirc remote. Rife with bad ideas (unbounded memory usage, passing inputs to shell commands, woo!), but works nicely and compiles beautifully to ARM using goxc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"log" | |
"html" | |
"os/exec" | |
) | |
func main() { | |
colors := []string{} | |
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) { | |
w.Header().Add("content-type", "text/html") | |
color := r.URL.Path[1:] | |
_,err := exec.Command("irsend", "send_once", "sylvania.conf", color).Output() | |
if err != nil { | |
log.Print(err) | |
} | |
colors = append(colors, color) | |
fmt.Fprintf(w, "<ul>") | |
for i := range(colors) { | |
fmt.Fprintf(w, "<li><a href='/%s'>%s</a></li>", html.EscapeString(colors[i]), html.EscapeString(colors[i])) | |
} | |
fmt.Fprintf(w, "</ul>") | |
}) | |
log.Fatal(http.ListenAndServe(":8585", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment