forked from jimmykuu/gopher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (39 loc) · 785 Bytes
/
Copy pathmain.go
File metadata and controls
51 lines (39 loc) · 785 Bytes
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
44
45
46
47
48
49
50
51
/*
读取配置文件,设置URL,启动服务器
*/
package main
import (
"code.google.com/p/gorilla/mux"
"encoding/json"
"net/http"
"os"
)
var config map[string]string
// 初始化,读取配置文件
func init() {
file, err := os.Open("config.json")
if err != nil {
println("配置文件读取失败")
panic(err)
os.Exit(1)
}
defer file.Close()
dec := json.NewDecoder(file)
err = dec.Decode(&config)
if err != nil {
println("配置文件读取失败")
panic(err)
os.Exit(1)
}
}
func main() {
http.Handle("/static/", http.FileServer(http.Dir(".")))
r := mux.NewRouter()
for url, handler := range handlers {
r.HandleFunc(url, handler)
}
http.Handle("/", r)
port := config["port"]
println("Listen", port)
http.ListenAndServe(":"+port, nil)
}