Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 1 day 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 (6 months ago)
- Default Branch: master
- Last Pushed: 2024-08-12T18:47:00.000Z (5 months ago)
- Last Synced: 2024-08-12T21:54:35.195Z (5 months 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[![Go Reference](https://pkg.go.dev/badge/github.com/cccaaannn/gohst.svg)](https://pkg.go.dev/github.com/cccaaannn/gohst) [![codecov](https://codecov.io/github/cccaaannn/gohst/graph/badge.svg?token=CM770U3IB4)](https://codecov.io/github/cccaaannn/gohst) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/cccaaannn/gohst) ![GitHub top language](https://img.shields.io/github/languages/top/cccaaannn/gohst?color=008B8B&style=flat-square) ![GitHub repo size](https://img.shields.io/github/repo-size/cccaaannn/gohst?color=FF6347&style=flat-square) [![GitHub](https://img.shields.io/github/license/cccaaannn/gohst?color=green&style=flat-square)](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 mainimport (
"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
```