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.
47 lines
799 B
47 lines
799 B
package main |
|
|
|
import ( |
|
"context" |
|
"html/template" |
|
"net/http" |
|
"os" |
|
"os/signal" |
|
"time" |
|
) |
|
|
|
var tmpl = template.Must(template.ParseFiles("static/index.html")) |
|
|
|
func main() { |
|
mux := http.NewServeMux() |
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) |
|
mux.HandleFunc("/", index) |
|
srv := &http.Server{ |
|
Addr: ":8080", |
|
Handler: mux, |
|
} |
|
|
|
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) |
|
defer stop() |
|
|
|
go func() { |
|
srv.ListenAndServe() |
|
}() |
|
|
|
<-ctx.Done() |
|
stop() |
|
|
|
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
|
defer cancel() |
|
|
|
srv.Shutdown(shutdownCtx) |
|
} |
|
|
|
func index(w http.ResponseWriter, r *http.Request) { |
|
data := struct { |
|
Title string |
|
}{ |
|
Title: "Title", |
|
} |
|
|
|
tmpl.Execute(w, data) |
|
}
|
|
|