shad-go/lectures/06-http/simpleserver/simpleserver.go

28 lines
508 B
Go
Raw Permalink Normal View History

2020-04-02 11:42:31 +00:00
package simpleserver
import (
"net/http"
)
func RunServer() {
handler := func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("pong"))
}
err := http.ListenAndServe(":8080", http.HandlerFunc(handler))
if err != nil {
panic(err)
}
}
func RunTLSServer() {
handler := func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("pong"))
}
err := http.ListenAndServeTLS(":8080", "cert.crt", "private.key", http.HandlerFunc(handler))
if err != nil {
panic(err)
}
}