feat: add Go server implementation with HTTPS support and update README for usage instructions
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
A simple HTTP server for connectivity testing. It can be run from the command line or in a container.
|
||||
|
||||
The Python version relies only on Python's standard library, so it should work in any environment with Python installed. The Node.js version also relies only on the standard library, so it should work in any environment with Node.js installed.
|
||||
The Python version relies only on Python's standard library, so it should work in any environment with Python installed. The Node.js version also relies only on the standard library, so it should work in any environment with Node.js installed. The Go version also relies only on the standard library, so it should work in any environment with Go installed.
|
||||
|
||||
It displays a simple HTML or plain-text page with the client's IP address and any detected `X-*` headers.
|
||||
|
||||
@@ -20,7 +20,8 @@ To run the server from the command line:
|
||||
python3 ok-server.py
|
||||
python3 ok-server.py --look basic
|
||||
python3 ok-server.py --bind 127.0.0.1 --port 8080 --look tailwind
|
||||
python3 ok-server.py --pem /path/to/bundle.pem --port 8443
|
||||
python3 ok-server.py --pem /path/to/bundle.pem
|
||||
python3 ok-server.py --pem /path/to/bundle.pem --tls-port 9443
|
||||
```
|
||||
|
||||
`--look` accepts `basic`, `nice`, `bootstrap`, or `tailwind`.
|
||||
@@ -28,13 +29,22 @@ You can override the look per request with the `look` query parameter, for examp
|
||||
`http://localhost:8080/?look=tailwind`
|
||||
|
||||
`--pem` accepts a path to a PEM file containing the certificate chain and private key.
|
||||
When provided, the server listens on HTTPS instead of plain HTTP.
|
||||
When provided, the server listens on both HTTP (`--port`, default 8080) and HTTPS (`--tls-port`, default 8443).
|
||||
|
||||
```bash
|
||||
node ok-server.mjs
|
||||
node ok-server.mjs --look basic
|
||||
node ok-server.mjs --bind 127.0.0.1 --port 8080 --look tailwind
|
||||
node ok-server.mjs --pem /path/to/bundle.pem --port 8443
|
||||
node ok-server.mjs --pem /path/to/bundle.pem
|
||||
node ok-server.mjs --pem /path/to/bundle.pem --tls-port 9443
|
||||
```
|
||||
|
||||
```bash
|
||||
go run ok-server.go
|
||||
go run ok-server.go --look basic
|
||||
go run ok-server.go --bind 127.0.0.1 --port 8080 --look tailwind
|
||||
go run ok-server.go --pem /path/to/bundle.pem
|
||||
go run ok-server.go --pem /path/to/bundle.pem --tls-port 9443
|
||||
```
|
||||
|
||||
Connect to the server using a web browser or a tool like `curl`:
|
||||
@@ -43,6 +53,27 @@ Connect to the server using a web browser or a tool like `curl`:
|
||||
curl -si "http://localhost:8080"
|
||||
```
|
||||
|
||||
### Building a Go binary
|
||||
|
||||
Cross-compile for any platform from any machine:
|
||||
|
||||
```bash
|
||||
# Linux amd64
|
||||
GOOS=linux GOARCH=amd64 go build -o ok-server-linux-amd64 ok-server.go
|
||||
|
||||
# Linux arm64
|
||||
GOOS=linux GOARCH=arm64 go build -o ok-server-linux-arm64 ok-server.go
|
||||
|
||||
# macOS arm64 (Apple Silicon)
|
||||
GOOS=darwin GOARCH=arm64 go build -o ok-server-darwin-arm64 ok-server.go
|
||||
|
||||
# macOS amd64 (Intel)
|
||||
GOOS=darwin GOARCH=amd64 go build -o ok-server-darwin-amd64 ok-server.go
|
||||
|
||||
# Windows amd64
|
||||
GOOS=windows GOARCH=amd64 go build -o ok-server-windows-amd64.exe ok-server.go
|
||||
```
|
||||
|
||||
### Docker
|
||||
|
||||
Use the included `Dockerfile` to build and run the server in a Docker container:
|
||||
|
||||
Reference in New Issue
Block a user