A simple http server
- Simple usage
- Path parsing
- TLS support
- Middlewares
go get github.com/cccaaannn/gohst
package main
import (
"fmt"
"github.com/cccaaannn/gohst"
)
func main() {
server := gohst.CreateServer()
server.AddHandler("GET /hi/:name", func(req *gohst.Request, res *gohst.Response) {
name := req.Params["name"]
res.Body = fmt.Sprintf(`
<body>
<h1>Hello %s!</h1>
</body>
`, name)
})
server.AddHandler("/*", func(req *gohst.Request, res *gohst.Response) {
res.StatusCode = 404
res.Body = `
<body>
<h1>404</h1>
</body>
`
})
stop, _ := server.ListenAndServe(":8080")
<-stop
}
go test -v
go test -coverprofile=coverage.out
go tool cover -html=coverage.out