Coder Social home page Coder Social logo

weesvc-gorilla's Introduction

WeeSVC Gorilla

Implementation of the WeeSVC application using Go and the Gorilla Mux web toolkit.

Ingredients

The following external libraries were directly utilized in this project.

Package Link Description
Go https://golang.org/ Well...it's obvious isn't it?!
Gorilla Mux https://www.gorillatoolkit.org/pkg/mux Web Toolkit providing HTTP server and routing
GORM https://gorm.io/ Database ORM
SQLite https://www.sqlite.org/index.html The lightweight database
Cobra https://github.com/spf13/cobra Command-line library
Viper https://github.com/spf13/viper Awesome configuration library for settings
Logrus https://github.com/sirupsen/logrus Logging abstraction for the Go standard library
UUID https://github.com/google/uuid Implementation for generation of universally unique identifiers (UUIDs)

Build

Builds are performed using the Makefile provided in the project root.

CLI

In order to build the CLI, you will need to have Go (1.13+) installed on your system.

The default target for the Makefile will perform several tasks:

  • organize imports using goimports
  • format code using gofmt
  • perform linting using golint
  • vet code for errors using go vet
  • compile binary for the current platform

☝️ NOTE: To initially build the project, you may need to run the make setup command to install the tools utilized for builds.

Once built, you can migrate the database scripts and run the application:

$ bin/weesvc migrate; bin/weesvc serve

Docker

For those who do not have Go available, Docker is an option to build the application and run the application within a container. Using the make build-docker command will build the application within a Linux container, then copy the resulting binary into a slim docker image to utilize for execution.

Once the the image is available, you can simply run the provided script which will open a browser to access the service at http://localhost:9092/api/hello .

$ ./docker-run.sh

☝️ NOTE: the docker-run.sh script is setup to not maintain state between executions. This means each time you start the container, you will be starting with a freshly created database.

Using the Application

Update the DatabaseURI setting in your config.yaml for the absolute path to the base project directory, i.e. the path for the directory containing this README.

☝️ TIP: Use the very cool HTTPie application for testing locally from the command-line.

Execute a GET command to retrieve the available places from the database.

$ http GET localhost:9092/api/places

HTTP/1.1 200 OK
Content-Length: 2
Content-Type: application/json
Date: Sat, 25 Jan 2020 05:33:57 GMT

[]

Add a place into the database using a POST command.

$ http POST localhost:9092/api/places name=NISC desc="NISC Lake St. Louis Office" lat:=38.7839 lon:=90.7878

HTTP/1.1 200 OK
Content-Length: 8
Content-Type: application/json
Date: Sat, 25 Jan 2020 05:34:08 GMT

{
    "id": 1
}

Run the GET command again to retrieve places which now include your newly added place!

$ http GET localhost:9092/api/places/1

HTTP/1.1 200 OK
Content-Length: 217
Content-Type: application/json
Date: Sat, 25 Jan 2020 05:34:18 GMT

[
    {
        "CreatedAt": "2020-01-24T23:34:08.491999-06:00",
        "DeletedAt": null,
        "Description": "NISC Lake St. Louis Office",
        "ID": 1,
        "Latitude": 38.7839,
        "Longitude": 90.7878,
        "Name": "NISC",
        "UpdatedAt": "2020-01-24T23:34:08.491999-06:00"
    }
]

Use the PATCH command to update a specific value. For example we'll update the Description as follows:

$ http PATCH localhost:9092/api/places/1 desc="Lake St. Louis"

HTTP/1.1 200 OK
Content-Length: 203
Content-Type: application/json
Date: Sat, 25 Jan 2020 18:13:13 GMT

{
    "CreatedAt": "2020-01-24T23:34:08.491999-06:00",
    "DeletedAt": null,
    "Description": "Lake St. Louis",
    "ID": 1,
    "Latitude": 38.7839,
    "Longitude": 90.7878,
    "Name": "NISC",
    "UpdatedAt": "2020-01-25T12:13:13.351201-06:00"
}

This returns the newly "patched" version of the place. Next we'll remove the row using the DELETE method.

$ http DELETE localhost:9092/api/places/1

HTTP/1.1 200 OK
Content-Length: 21
Content-Type: application/json
Date: Sat, 25 Jan 2020 18:15:16 GMT

{
    "message": "removed"
}

weesvc-gorilla's People

Contributors

javaducky avatar

Watchers

 avatar  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.