https://github.com/cccaaannn/gohst
Go HTTP Server Tool
https://github.com/cccaaannn/gohst
codecov go go-http-server go-package gohst http http-server simple-server
Last synced: about 1 year ago
JSON representation
Go HTTP Server Tool
- Host: GitHub
- URL: https://github.com/cccaaannn/gohst
- Owner: cccaaannn
- License: mit
- Created: 2024-07-25T21:49:00.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-12T18:47:00.000Z (over 1 year ago)
- Last Synced: 2025-01-21T12:13:19.599Z (about 1 year ago)
- Topics: codecov, go, go-http-server, go-package, gohst, http, http-server, simple-server
- Language: Go
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gohst
### Go HTTP Server Tool
A simple http server
[](https://pkg.go.dev/github.com/cccaaannn/gohst) [](https://codecov.io/github/cccaaannn/gohst)    [](https://github.com/cccaaannn/gohst/blob/master/LICENSE)
---
## Features
1. Simple usage
2. Path parsing
3. TLS support
4. Middlewares
## Usage
### Install package
```shell
go get github.com/cccaaannn/gohst
```
### Minimal example
```go
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(`
Hello %s!
`, name)
})
server.AddHandler("/*", func(req *gohst.Request, res *gohst.Response) {
res.StatusCode = 404
res.Body = `
404
`
})
stop, _ := server.ListenAndServe(":8080")
<-stop
}
```
### Other examples
1. [example/crud/main.go](/example/crud/main.go)
2. [example/tls/main.go](/example/tls/main.go)
3. [example/middleware/main.go](/example/middleware/main.go)
## Development
### Test
```shell
go test -v
```
### Coverage
```shell
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
```