Created
November 21, 2009 21:56
-
-
Save jakubkulhan/240300 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"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()); } | |
} |
This file contains 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
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