You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
567 B
39 lines
567 B
1 year ago
|
package server
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func index(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, "index")
|
||
|
|
||
|
}
|
||
|
|
||
|
func wsEndpoint(w http.ResponseWriter, r *http.Request) {
|
||
|
fmt.Fprintf(w, "hello")
|
||
|
}
|
||
|
|
||
|
func setupRoutes() {
|
||
|
http.HandleFunc("/", index)
|
||
|
http.HandleFunc("/ws", wsEndpoint)
|
||
|
|
||
|
}
|
||
|
|
||
|
func SetupAndRun(port string, sighup *chan bool) {
|
||
|
setupRoutes()
|
||
|
|
||
|
srv := &http.Server{Addr: port}
|
||
|
|
||
|
go func() {
|
||
|
<-*sighup
|
||
|
log.Println("Shutting down the webserver")
|
||
|
srv.Shutdown(context.TODO())
|
||
|
}()
|
||
|
|
||
|
log.Fatal(srv.ListenAndServe())
|
||
|
|
||
|
}
|