Simple HTTP server that gives you random color output.
This is originally created for testing Service Mesh. The server is meant to be really simple, but provides different output depending on how you start up the server.
The simplest way to get color-svc
server started is the following:
$ docker run -it --rm \
-p 8800:8800 \
rytswd/color-svc:latest color-svc
# Output
2020/12/17 13:12:22 Server setup complete.
Per Request Delay: Disabled
Red : Enabled
Green : Enabled
Blue : Enabled
Yellow : Enabled
CORS : Disabled
Logging : Enabled
Total Available Colors: 15
2020/12/17 13:12:22 Server starting
...
# More log lines will appear as request is handled
With the server running, you can use the following:
$ curl 'http://localhost:8800/random'
# Output
Generated Color
"Green" - with HEX "#008000"
Endpoint | Description |
---|---|
/random |
Generate random color, based on available color set |
/random/red |
Generate random redish color, returns error if disabled |
/random/green |
Generate random greenish color, returns error if disabled |
/random/blue |
Generate random bluish color, returns error if disabled |
/random/yellow |
Generate random yellowish color, returns error if disabled |
/SOME_COLOR |
Get specific color - SOME_COLOR is case insensitive, and when not found, you will get "unknown" |
Parameter | Description |
---|---|
?fmt=json |
Return JSON representation |
With Docker
The simplest way to get started is the following:
$ docker run -it --rm \
-p 8800:8800 \
rytswd/color-svc:latest color-svc
You can adjust the behaviour with providing environmental variables. For example, the below command will only provide bluish colors.
$ docker run -it --rm \
-p 8800:8800 \
-e DISABLE_RED=true \
-e DISABLE_GREEN=true \
-e DISABLE_YELLOW=true \
rytswd/color-svc:latest color-svc
Also, the container is pushed to GitHub Container Registry at ghcr.io/rytswd/color-svc
.
With Kubernetes
This repository contains example Kubernetes Service + Deployment YAMLs in /k8s directory.
You can use them as is, or adjust it as you like. There are some environmental variables that can adjust the server behaviours.
Example:
$ kubectl apply \
-f https://raw.githubusercontent.com/rytswd/color-svc/main/k8s/account.yaml \
-f https://raw.githubusercontent.com/rytswd/color-svc/main/k8s/color-svc-default.yaml
From code
Simply run with go run cmd/server/main.go
. You can provide environmental variables to adjust some behaviours.
The following environmental variables are read when the server starts up.
Env Name | Description | Default |
---|---|---|
ENABLE_DELAY |
Enable delay for all requests | false |
DELAY_DURATION_MILLISECOND |
Delay duration in millisecond, only used when delay is enabled | 1000 |
ENABLE_CORS |
Enable CORS | false |
DISABLE_LOGGING |
Disable per request logging | false |
DISABLE_RED |
Disable all redish colors | false |
DISABLE_GREEN |
Disable all greenish colors | false |
DISABLE_BLUE |
Disable all bluish colors | false |
DISABLE_YELLOW |
Disable all yellowish colors | false |