Coder Social home page Coder Social logo

hellogoservice's Introduction

HelloGoService

A simple REST service for demos (written in Go).
by William Mortl

This example collection of Go REST services demostrate several important Go principles:

  1. ping.go - a simple Go REST service
  2. hello.go - a Go REST service that reads from the query string
  3. dbadd.go & dbget.go - adds and retrieves records from an in-memory database, shows how to read JSON from the post body, and demonstrates how to read a variable from the REST path
  4. math.go - demonstrates Go routines... which is a Go "thread"

To Run

Visual Studio Code

This solution contains a devcontainer that allows one to run and debug this REST service within Visual Studio Code. For a tutorial on devcontainers, visit this link.

Simply go to the "Debug" icon (on the left) and click the "play" button (near the top).

Command Line

Building

  1. Clone the repository into your Go path
  2. In the project directory, first build the project using: make
  3. Next, again in the project directory, create a Docker container: docker build -t {image name}:{tag name} .

Running the Container

From the CLI, run the container: docker container run -p 8080:8080 -it {image name}:{tag}

Services Provided

REST Services Documentation

Ping service: http://localhost:8080/Ping

Hello service: http://localhost:8080/Hello?name=YourNameHere

Database Get service (retrieves by ID which is an int value, replace the trailing 0 with any int): http://localhost:8080/Db/0

Database Add / Update service (adds / updates by ID, replace the trailing 4 with any int): http://localhost:8080/Db/4

Post JSON in this format to the above URL to add this person to the database with id 4:

{
    "name": "Taylor Swift",
    "address": "10th Street",
    "phone": "6155551212",
}


Math service (allowed operators: Add, Subtract, Multiple): http://localhost:8080/Math/Add

Post JSON in this format to the above URL to sum the numbers below:

{
    "numbers": [
        1,
        2,
        3,
        4
    ]
}

Telemetry Metrics Documentation

Metrics are provided by Prometheus.

Prometheus metrics service: http://localhost:8080/metrics

Swagger Documentation

Service documentation provided by swaggo.

Swagger service: http://localhost:8080/swagger/index.html

hellogoservice's People

Contributors

williammortl avatar

Stargazers

Roman avatar

Watchers

 avatar

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.