-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
37 lines (30 loc) · 843 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
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
)
// http handlers
func main() {
router := mux.NewRouter()
/* change this to IP addr !! */
sub := router.Host("localhost").Subrouter()
sub.PathPrefix("/html/").Handler(http.StripPrefix("/html/", http.FileServer(http.Dir("html"))))
sub.HandleFunc("/", devHandler)
// gorilla mux var to handle different html outputs
sub.HandleFunc("/{sort}", devHandler)
// sd variable for specific service
sub.HandleFunc("/detail/{sd:[a-zA-Z0-9_-]+}", detailHandler)
// IdleTimeout requires go1.8
server := http.Server{
Addr: ":8082",
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
IdleTimeout: 120 * time.Second,
Handler: router,
}
fmt.Println("Server started at localhost:8082")
log.Fatal(server.ListenAndServe())
}