Skip to content

Instantly share code, notes, and snippets.

@jakubkulhan
Created November 21, 2009 21:56
Show Gist options
  • Save jakubkulhan/240300 to your computer and use it in GitHub Desktop.
Save jakubkulhan/240300 to your computer and use it in GitHub Desktop.
package main
import (
"http";
"io";
"time";
"flag";
"strconv";
)
var port = flag.Int("p", 1234, "port to listen to");
func init() { flag.Parse(); }
type HandlerString string
func (s HandlerString) ServeHTTP(c *http.Conn, req *http.Request) {
io.WriteString(c, string(s));
}
func main() {
mux := http.NewServeMux();
mux.Handle("/", http.HandlerFunc(func (c *http.Conn, r *http.Request) {
now := time.LocalTime();
io.WriteString(c, now.Asctime());
}));
mux.Handle("/hello", HandlerString("hello, world!"));
err := http.ListenAndServe(":" + strconv.Itoa(*port), mux);
if err != nil { panic("ListenAndServe:", err.String()); }
}
TARGET=$(notdir $(shell pwd))
MAGIC=$(shell (([ "$(GOARCH)" == "amd64" ] && echo 6) || ([ "$(GOARCH)" == "arm" ] && echo 5)) || echo 8)
all:
@for dir in `find * -type d`; do \
go=$$(find "$$dir" -maxdepth 1 -name "*.go"); \
if [ ! -z "$$go" ]; then \
echo "- $$dir: $$go"; \
$(MAGIC)g -I. -o _go_.8 $$go; \
rm -f $$dir.a; \
gopack grc $$dir.a _go_.8; \
fi \
done
@if [ -f 'main.go' ]; then \
$(MAGIC)g -I. -o _go_.8 main.go; \
$(MAGIC)l -o $(TARGET) _go_.8; \
fi
@rm -f _go_.8
clean:
@rm -f _go_.8 `find * -name "*.a"` $(TARGET)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment