-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
43 lines (36 loc) · 964 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"flag"
"log"
"net/http"
"os"
"github.com/gorilla/handlers"
"github.com/gorilla/mux"
"fmt"
)
func PingHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("pong\n"))
}
func main() {
webroot := "/var/www"
bind := "localhost:8000"
flag.StringVar(&webroot, "webroot", "/var/www", "web application root")
flag.StringVar(&bind, "bind", "localhost:8000", "<host>:<port> or just <host> or <port>")
flag.Parse()
log.Println(" .-------.")
log.Println(" [|( ◔ ౪◔)|] ")
log.Println("")
log.Println(fmt.Sprintf("Bound to; %v", bind))
r := mux.NewRouter()
r.HandleFunc("/ping", PingHandler)
r.HandleFunc("/settings", SettingsHandler)
r.HandleFunc("/test/lastfm", testArtistSearch)
r.PathPrefix("/").Handler(
handlers.LoggingHandler(os.Stdout,
http.FileServer(http.Dir(webroot))))
//r.HandleFunc("/socket.io", SocketHandler)
err := http.ListenAndServe(bind, r)
if err != nil {
panic(err)
}
}