Add command line parsing
This commit is contained in:
parent
6f59c88ba1
commit
6ef5374f09
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -10,6 +11,12 @@ import (
|
||||||
"willnorris.com/go/microformats"
|
"willnorris.com/go/microformats"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var port int
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.IntVar(&port, "port", 80, "port for serving api")
|
||||||
|
}
|
||||||
|
|
||||||
type microsubHandler struct {
|
type microsubHandler struct {
|
||||||
Backend microsub.Microsub
|
Backend microsub.Microsub
|
||||||
}
|
}
|
||||||
|
@ -196,9 +203,25 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
backend := loadMemoryBackend()
|
flag.Parse()
|
||||||
//backend := createMemoryBackend()
|
|
||||||
|
createBackend := false
|
||||||
|
args := flag.Args()
|
||||||
|
|
||||||
|
if len(args) >= 1 {
|
||||||
|
if args[0] == "new" {
|
||||||
|
createBackend = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var backend microsub.Microsub
|
||||||
|
|
||||||
|
if createBackend {
|
||||||
|
backend = createMemoryBackend()
|
||||||
|
} else {
|
||||||
|
backend = loadMemoryBackend()
|
||||||
|
}
|
||||||
|
|
||||||
http.Handle("/microsub", µsubHandler{backend})
|
http.Handle("/microsub", µsubHandler{backend})
|
||||||
log.Fatal(http.ListenAndServe(":80", nil))
|
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user