https://github.com/pdrb/gecho
Simple http "echo" server written with Go stdlib.
https://github.com/pdrb/gecho
echo-http go http-echo http-server stdlib
Last synced: 26 days ago
JSON representation
Simple http "echo" server written with Go stdlib.
- Host: GitHub
- URL: https://github.com/pdrb/gecho
- Owner: pdrb
- License: mit
- Created: 2024-10-28T00:36:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-30T01:43:47.000Z (over 1 year ago)
- Last Synced: 2025-09-17T21:05:46.666Z (6 months ago)
- Topics: echo-http, go, http-echo, http-server, stdlib
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gecho
[](https://goreportcard.com/report/github.com/pdrb/gecho)
[](https://github.com/pdrb/gecho/actions/workflows/ci.yml)
[](https://github.com/pdrb/gecho/blob/main/LICENSE)
Simple http "echo" server written in Go using only the standard library.
The request will be parsed and the response will be a prettified (indented) json with the request data.
Duplicated headers and params are supported and will be comma separated in the response.
The origin IP will be extracted from headers (X-Real-IP, X-Forwarded-For, etc...) or directly from remote address.
## Install
Install compiling from source using Go:
```shell
go install github.com/pdrb/gecho@latest
```
## Usage
```text
Usage: gecho [options]
A simple http "echo" server written in Go
Options:
-h, --help Show this help message and exit
-l, --listen Listen address (default: ":8090")
-t, --timeout Server timeout in seconds (default: 60)
-v, --version Show version and exit
Example: gecho --listen 0.0.0.0:80
```
## Example
The following `curl`:
```shell
curl -X POST 'http://localhost:8090/headers?name=John&food=apple&food=banana&age=32' \
-H 'H1: Header 1' \
-H 'H1: Repeated Header 1' \
-H "X-Auth: 1234" \
-H 'Content-Type: application/json' \
-d '{"foo": "bar", "foo": "baz"}'
```
Should return a response like:
```json
{
"data": "{\"foo\": \"bar\", \"foo\": \"baz\"}",
"headers": {
"Accept": "*/*",
"Content-Length": "28",
"Content-Type": "application/json",
"H1": "Header 1,Repeated Header 1",
"User-Agent": "curl/7.81.0",
"X-Auth": "1234"
},
"json": {
"foo": "bar",
"foo": "baz"
},
"method": "POST",
"origin": "127.0.0.1",
"params": {
"age": "32",
"food": "apple,banana",
"name": "John"
},
"url": "http://localhost:8090/headers?name=John&food=apple&food=banana&age=32"
}
```
Server log:
```text
$ gecho --listen 127.0.0.1:8090
2024/10/29 22:25:04 INFO starting server address=127.0.0.1:8090 timeout=60 version=1.2.0
2024/10/29 22:25:07 INFO handled request method=POST path=/headers addr=127.0.0.1:57488 elapsed=95.89µs
```