Coder Social home page Coder Social logo

color-svc's Introduction

color-svc

Simple HTTP server that gives you random color output.

Build Status | License: MIT | GitHub Release Date | Docker Image Version (latest semver)

๐ŸŒ… Contents

โ“ Why and What is this for?

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.

๐Ÿš€ Getting Started

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"

๐Ÿšฅ Available Endpoints

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"

๐Ÿงช Request Parameters

Parameter Description
?fmt=json Return JSON representation

๐Ÿ How to use

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.

โš™๏ธ Server Configurations

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

color-svc's People

Contributors

rytswd avatar sryoya avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sryoya

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.