{"id":16569982,"url":"https://github.com/andygrunwald/simple-webserver","last_synced_at":"2025-10-29T01:30:18.162Z","repository":{"id":138434881,"uuid":"42177399","full_name":"andygrunwald/simple-webserver","owner":"andygrunwald","description":"A small webserver for testing various technologies, techniques and concepts written in Go.","archived":false,"fork":false,"pushed_at":"2021-06-22T17:11:02.000Z","size":42,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-01T20:51:12.178Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andygrunwald.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"andygrunwald","custom":"https://paypal.me/andygrunwald"}},"created_at":"2015-09-09T12:38:00.000Z","updated_at":"2023-11-13T07:45:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"db79391e-ddf3-433c-a8fe-6b96ea116566","html_url":"https://github.com/andygrunwald/simple-webserver","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fsimple-webserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fsimple-webserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fsimple-webserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andygrunwald%2Fsimple-webserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andygrunwald","download_url":"https://codeload.github.com/andygrunwald/simple-webserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238751732,"owners_count":19524627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T21:16:12.285Z","updated_at":"2025-10-29T01:30:17.824Z","avatar_url":"https://github.com/andygrunwald.png","language":"Go","funding_links":["https://github.com/sponsors/andygrunwald","https://paypal.me/andygrunwald"],"categories":[],"sub_categories":[],"readme":"# simple-webserver\n\n[![Build Status](https://travis-ci.org/andygrunwald/simple-webserver.svg?branch=master)](https://travis-ci.org/andygrunwald/simple-webserver)\n[![GoDoc](https://godoc.org/github.com/andygrunwald/simple-webserver?status.svg)](https://godoc.org/github.com/andygrunwald/simple-webserver)\n[![Go Report Card](https://goreportcard.com/badge/github.com/andygrunwald/simple-webserver)](https://goreportcard.com/report/github.com/andygrunwald/simple-webserver)\n\nA small webserver (written in [Go](http://golang.org/)) for testing various technologies, techniques and concepts like [Docker](https://www.docker.com/), [Marathon](https://mesosphere.github.io/marathon/) / [Apache Mesos](http://mesos.apache.org/), [Kubernetes](http://kubernetes.io/), [API Blueprint](https://apiblueprint.org/) and others.\n\nAll guides how to use, play and use a technique or concept are documented here. Feel free to play around and learn as much as i do.\n\n---\n\n## Table of Contents\n\n1. [Batteries Included](#batteries-included)\n2. [Why this project?](#why-this-project)\n3. [Build instructions](#build-instructions)\n\t1. [Native application](#native-application)\n\t2. [Docker](#docker)\n4. [Tryout everything](#tryout-everything)\n\t1. [Native application](#native-application-1)\n\t2. [Docker](#docker-1)\n\t3. [Docker Compose](#docker-compose)\n\t3. [Marathon (native application)](#marathon-native-application)\n\t4. [Marathon (docker container)](#marathon-docker-container)\n\t5. [Marathon incl. Redis backend (docker container)](#marathon-incl-redis-backend-docker-container)\n\t6. [Kubernetes](#kubernetes)\n\t7. [API Blueprint: Validating API description](#api-blueprint-validating-api-description)\n\t8. [API Blueprint: Generating API docs](#api-blueprint-generating-api-docs)\n5. [Things on the list to try](#things-on-the-list-to-try)\n6. [Contact](#contact)\n7. [License](#license)\n\n## Batteries Included\n\nHere you will find a list of tested technologies, techniques and concepts within this project:\n\n* [Go](http://golang.org/): How to write a small webserver with a minimal [Redis](http://redis.io/) backend in this programming language (incl. [GoDoc](https://godoc.org/github.com/andygrunwald/simple-webserver) and [unit tests](./main_test.go))\n* [12factor](https://12factor.net/config): Configure an application via environment variables\n* [Travis CI](https://travis-ci.org/): Execute unit tests on every push and pull request\n* [Docker](https://www.docker.com/): How to isolate a Go app in a docker container\n* [Docker Compose](https://docs.docker.com/compose/): How to start a multi-container setup with one command\n* [Marathon](https://mesosphere.github.io/marathon/) @ [Apache Mesos](http://mesos.apache.org/): How to deploy this app on a Marathon cluster (native and in a docker container)\n* [Kubernetes](http://kubernetes.io/): How to deploy this app on a Kubernetes cluster\n* [API Blueprint](https://apiblueprint.org/): API development based on markdown specifications inclusive API doc generation by [aglio](https://github.com/danielgtaylor/aglio) and validation by [dredd](https://github.com/apiaryio/dredd)\n\n## Why this project?\n\nThe information technology and computer science world is getting crazy.\nEvery day new tooling will be released, new techniques comes up and some concepts are getting best practice.\n\n**It is important to stay up to date and this is the really hard part here.**\n\nThis project is my personal playground to try out all the new things i am excited of.\nI am aware that this project is not representative and comparable with a real products that solves problems of the world.\nThose projects are much more complex and have several other dependencies.\nBut the simplicity of this projects is on purpose and enables me to get a first idea and feeling of the topic i want to try in a small amount of time.\n\n## Build instructions\n\n### Native application\n\nFor building the native webserver you need a running [Go installation](https://golang.org/doc/install).\n\n```sh\n$ go build -o simple-webserver .\n```\n\nTo compile it for a different OS (e.g. linux) use\n\n```sh\n$ GOOS=linux go build -o simple-webserver .\n```\n\nPrecompiled binaries for various operating systems can be found in our [releases](https://github.com/andygrunwald/simple-webserver/releases).\n\nIf you want to execute the unit tests, run\n\n```sh\n$ go test -v ./...\n```\n\n### Docker\n\nFor building the docker image you need a running [Docker engine](https://docs.docker.com/engine/installation/).\n\n```sh\n$ docker build -t andygrunwald/simple-webserver .\n```\n\nOr you use the existing images from [Docker Hub](https://hub.docker.com/r/andygrunwald/simple-webserver/).\n\n## Tryout everything\n\n### Native application\n\nThe general usage of *simple-webserver* is\n\n```sh\n$ ./simple-webserver -help\nUsage of ./simple-webserver:\n  -listen string\n    \tAddress + Port to listen on. Format ip:port. Environment variable: SIMPLE_WEBSERVER_LISTEN (default \":8082\")\n  -redis string\n    \tAddress + Port where a redis server is listening. Environment variable: SIMPLE_WEBSERVER_REDIS (default \":6379\")\n```\n\nStart the webserver with\n\n```sh\n$ ./simple-webserver\n2016/06/05 14:57:18 Starting webserver and listen on :8082\n```\n\nand send your first request\n\n```sh\n$ curl http://localhost:8082/version\nsimple webserver v1.1.1\n```\n\nIf you have a Redis server available, you can apply it via command line flag:\n\n```sh\n$ ./simple-webserver -redis \":6379\"\n2016/06/05 14:57:18 Starting webserver and listen on :8082\n```\n\nand call a `/ping` request\n\n```sh\n$ curl http://localhost:8082/ping\nPONG\n```\n\n### Docker\n\nStart the container with\n\n```sh\n$ docker run -d -p 8082:8082 andygrunwald/simple-webserver\n9b20babef443420bf1728583fbfba......\n```\n\nand send your first request\n\n```sh\n$ curl http://DOCKER-IP:8082/version\nsimple webserver v1.1.1\n```\n\nOr launch *simple-webserver* with a Redis backend\n\n```sh\n$ docker run --name simple-webserver-redis -d redis\n$ docker run -d -p 8082:8082 \\\n\t\t\t\t--link simple-webserver-redis:redis \\\n\t\t\t\tandygrunwald/simple-webserver -redis \"redis:6379\"\n```\n\nFor further information the docker image is available at [Docker Hub](https://hub.docker.com/r/andygrunwald/simple-webserver/).\n\n### Docker Compose\n\nFire up *simple-webserver* with a Redis backend with\n\n```sh\n$ docker-compose up -d\n```\n\nand call a `/ping` request\n\n```sh\n$ curl http://DOCKER-IP:8082/ping\nPONG\n```\n\n### Marathon (native application)\n\nStart the native application on a [Marathon](https://github.com/mesosphere/marathon) cluster (scheduling framework for [Apache Mesos](http://mesos.apache.org/) with\n\n```sh\n$ curl -X POST -H \"Content-Type: application/json\" http://marathon:8080/v2/apps -d@marathon.json\n{\n    \"id\": \"/simple-webserver\",\n    ...\n}\n```\n\nPlease visit your Marathon UI at http://marathon:8080/ to see if the deployment works out.\n\nIf you use Marathon in combination with [haproxy-marathon-bridge](https://open.mesosphere.com/tutorials/service-discovery/) or another [service discovery](https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html) solution your service is available via the **service port 11000**\n\n```sh\n$ curl http://marathon-node:11000/version\nsimple webserver v1.1.1\n```\n\nIf you don`t have a Mesos / Marathon cluster, i highly recommend [bobrik/mesos-compose](https://github.com/bobrik/mesos-compose).\n\n### Marathon (docker container)\n\nStart the docker container on a [Marathon](https://github.com/mesosphere/marathon) cluster (scheduling framework for [Apache Mesos](http://mesos.apache.org/) with\n\n```sh\n$ curl -X POST -H \"Content-Type: application/json\" http://marathon:8080/v2/apps -d@marathon-docker.json\n{\n    \"id\":\"/simple-webserver-docker\",\n    ...\n}\n```\n\nPlease visit your Marathon UI at http://marathon:8080/ to see if the deployment works out.\n\nIf you use Marathon in combination with [haproxy-marathon-bridge](https://open.mesosphere.com/tutorials/service-discovery/) or another [service discovery](https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html) solution your service is available via the **service port 11001**\n\n```sh\n$ curl http://marathon-node:11001/version\nsimple webserver v1.1.1\n```\n\nIf you don`t have a Mesos / Marathon cluster, i highly recommend [bobrik/mesos-compose](https://github.com/bobrik/mesos-compose).\n\n### Marathon incl. Redis backend (docker container)\n\nStart the docker container with a Redis backend on a [Marathon](https://github.com/mesosphere/marathon) cluster (scheduling framework for [Apache Mesos](http://mesos.apache.org/) with\n\n```sh\n$ curl -X POST -H \"Content-Type: application/json\" http://marathon:8080/v2/groups -d@marathon-redis-docker.json\n{\n    \"version\":\"2016-06-18T16:01:45.739Z\",\n    ...\n}\n```\n\nPlease visit your Marathon UI at http://marathon:8080/ to see if the deployment works out.\n\nIf it doesn't work out, please check `constraints` value in [marathon-redis-docker.json](./marathon-redis-docker.json) if this is equal the IP of your Mesos slave. If not, adjust it accordingly.\n\nIf you use Marathon in combination with [haproxy-marathon-bridge](https://open.mesosphere.com/tutorials/service-discovery/) or another [service discovery](https://mesosphere.github.io/marathon/docs/service-discovery-load-balancing.html) solution your service is available via the **service port 11001**\n\n```sh\n$ curl http://marathon-node:11001/ping\nPONG\n```\n\nIf you don`t have a Mesos / Marathon cluster, i highly recommend [bobrik/mesos-compose](https://github.com/bobrik/mesos-compose).\n\n### Kubernetes\n\nIn this section we assume you have already a running Kubernetes cluster incl. a configured [kubectl](http://kubernetes.io/docs/user-guide/prereqs/). Otherwise i recommend to read [Getting Started With A Local Kubernetes Environment](https://blog.giantswarm.io/getting-started-with-a-local-kubernetes-environment/) or [Installing/Setting Up Kubernetes @ Kubernetes Docs](http://kubernetes.io/docs/).\n\nIn the [kubernetes.yaml](./kubernetes.yaml) you will find definitions for [Deployments](http://kubernetes.io/docs/user-guide/deployments/), [Services](http://kubernetes.io/docs/user-guide/services/) and an [Ingress Resource](http://kubernetes.io/docs/user-guide/ingress/).\nThis definition will start the *simple-webserver* incl. a Redis instance.\n\nSo lets start.\nApply the definition:\n\n```sh\n$ kubectl apply --filename kubernetes.yaml\nservice \"simple-webserver\" created\ndeployment \"simple-webserver\" created\nservice \"simple-webserver-redis\" created\ndeployment \"simple-webserver-redis\" created\ningress \"simple-webserver\" created\n```\n\nCheck if all deployments are there:\n\n```sh\n$ kubectl get deployment -l app=simple-webserver\nNAME                     DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE\nsimple-webserver         1         1         1            1           24s\nsimple-webserver-redis   1         1         1            1           24s\n```\n\nCheck the services:\n\n```sh\n$ kubectl get svc -l app=simple-webserver\nNAME                     CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE\nsimple-webserver         172.31.0.20    \u003cnodes\u003e       8082:30658/TCP   51s\nsimple-webserver-redis   172.31.0.238   \u003cnone\u003e        6379/TCP         50s\n```\n\nAnd have a look at your [pods](http://kubernetes.io/docs/user-guide/pods/):\n\n```\n$ kubectl get pods -l app=simple-webserver\nNAME                                      READY     STATUS    RESTARTS   AGE\nsimple-webserver-494066648-8dkhm          1/1       Running   0          1m\nsimple-webserver-redis-1815988752-09qog   1/1       Running   0          1m\n```\n\nDepending on your configuration *simple-webserver* should be accessible under your public ip / address via the Ingress resource.\n\nTo clean it up and delete it, fire:\n\n```sh\n$ kubectl delete service,deployment,ingress simple-webserver\nservice \"simple-webserver\" deleted\ndeployment \"simple-webserver\" deleted\ningress \"simple-webserver\" deleted\n$ kubectl delete service,deployment simple-webserver-redis\nservice \"simple-webserver-redis\" deleted\ndeployment \"simple-webserver-redis\" deleted\n```\n\n### API Blueprint: Validating API description\n\n[API Blueprint](https://apiblueprint.org/) is a powerful high-level API description language for web APIs.\nBased on out definition file [api-blueprint.apib](./api-blueprint.apib) we are able to ...\n\n... validate our API implementation (in *simple-webserver*) based on our API description / apib file with [dredd](https://github.com/apiaryio/dredd).\ndredd will analyze the description and generate HTTP tests and fire them against a running instance of *simple-webserver*.\n\nAt first start an instance of simple-webserver. You can choose your favorite way. Native, Docker, Marathon, etc. Doesn't matter.\n\nAfter this, run *dredd* tests in a docker container:\n\n```sh\n$ docker run -it --rm \\\n\t\t\t\t--net host \\\n\t\t\t\t-v /HOST/PATH/TO/simple-webserver:/simple-webserver \\\n\t\t\t\tapiaryio/dredd \\\n\t\t\t\tdredd simple-webserver/api-blueprint.apib http://INSTANCE:8082\ninfo: Beginning Dredd testing...\npass: HEAD / duration: 30ms\n...\n```\n\nPlease replace\n\n* `/HOST/PATH/TO/simple-webserver` with an absolute path to a local copy of *simple-webserver* on your machine\n* `http://INSTANCE:8082` with IP:Port of a running instance of *simple-webserver*\n\n### API Blueprint: Generating API docs\n\n[API Blueprint](https://apiblueprint.org/) is a powerful high-level API description language for web APIs.\nBased on out definition file [api-blueprint.apib](./api-blueprint.apib) we are able to ...\n\n... generate our API documentation with [aglio](https://github.com/danielgtaylor/aglio).\n\n```sh\n$ docker run -ti --rm \\\n\t\t\t\t-v `pwd`:/docs \\\n\t\t\t\thumangeo/aglio -i api-blueprint.apib -o /docs/output.html\n```\n\nAfter this you can will find a new file `output.html` in the current directory.\nOpen it and you should see you API documentation.\n\n## Things on the list to try\n\n* [Blue-Green Deployment with Marathon](https://mesosphere.github.io/marathon/docs/blue-green-deploy.html)\n\n## Contact\n\nYou are more than welcome to [open issues](https://github.com/andygrunwald/simple-webserver/issues) and / or [send pull requests](https://github.com/andygrunwald/simple-webserver/pulls) if you found a typo, a bug, need help to try something or want to request a new feature.\n\n**If you appreciate this project please feel free to drop me a line and tell me!*\nIt's always nice to hear from people who have benefitted from this work and pushes the motivation again.**\n\n* Twitter: [@andygrunwald](https://twitter.com/andygrunwald)\n* Email: Checkout the mail at [my github profile](https://github.com/andygrunwald)\n\n## License\n\nThis project is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandygrunwald%2Fsimple-webserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandygrunwald%2Fsimple-webserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandygrunwald%2Fsimple-webserver/lists"}