-
Notifications
You must be signed in to change notification settings - Fork 0
/
webserver.go
52 lines (43 loc) · 898 Bytes
/
webserver.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
44
45
46
47
48
49
50
51
52
// A basic HTTP server.
// By default, it serves the current working directory on port 8080.
package main
import (
"log"
"net/http"
"encoding/json"
"io/ioutil"
"fmt"
"os"
)
var (
ConfigFile = "config.json"
Address = ""
Port = ""
Dir = ""
c Config
)
// struct for loading configuration information
type Config struct {
Address string
Port string
Dir string
Tmpfile string
}
func init() {
// open our config and parse
confBytes, e := ioutil.ReadFile(ConfigFile)
if e != nil {
fmt.Println(e.Error())
os.Exit(1)
}
if e := json.Unmarshal(confBytes, &c); e != nil {
fmt.Println(e.Error())
os.Exit(2)
}
}
func main() {
listen := c.Address + ":" + c.Port
log.Printf("listening on %q...", listen)
err := http.ListenAndServe(listen, http.FileServer(http.Dir(c.Dir)))
log.Fatalln(err)
}