-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp.go
More file actions
31 lines (26 loc) · 697 Bytes
/
http.go
File metadata and controls
31 lines (26 loc) · 697 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
package main
import (
"fmt"
"net/http"
)
// initHTTP initializes the HTTP server.
func (b *bot) initHTTP() {
if b.HTTP.EnableEcho {
b.initEcho()
}
// Handle all routing from here.
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
b.HTTP.logger.Printf("%s %s from %s", r.Method, r.URL.Path, r.RemoteAddr)
if b.HTTP.EnableEcho && r.URL.Path == b.HTTP.EchoRoute && r.Method == b.HTTP.EchoMethod {
b.echoHandler(w, r)
} else {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintf(w, "404")
}
})
// Fire up the server in a goroutine so that we aren't blocking.
go func() {
http.ListenAndServe(b.HTTP.Address+":"+b.HTTP.Port, nil)
b.mainWG.Done()
}()
}