-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
41 lines (36 loc) · 889 Bytes
/
server.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
package main
import (
"errors"
"flag"
"log"
"net/http"
"os"
)
var CACHETIME int64
func main() {
CACHETIME = 60 * 60 * 24
file, logerr := os.OpenFile("mtmt-publist.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if logerr != nil {
log.Fatal(logerr)
}
log.SetOutput(file)
mux := http.NewServeMux()
mux.HandleFunc("/user", handleGetUser)
mux.HandleFunc("/institute", handleGetInstitute)
mux.HandleFunc("/alive", func(w http.ResponseWriter, r *http.Request) {
log.Printf("alive")
w.WriteHeader(http.StatusOK)
w.Write([]byte("200 - alive"))
},
)
var port string
flag.StringVar(&port, "port", "3333", "specify port")
flag.Parse()
servererr := http.ListenAndServe(":"+port, mux)
if errors.Is(servererr, http.ErrServerClosed) {
log.Println("server closed")
} else if servererr != nil {
log.Printf("error starting server: %s\n", servererr)
os.Exit(1)
}
}