You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/caarlos0/go-web-api-example

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/caarlos0/go-web-api-example

v0.0.0-20170630205513-f6d89b204c9e
Source
Go
Version published
Created
Source

go-web-api-example

Why?

The idea is to provide a sample architecture for web API's written in Go, using PostgreSQL as database and Prometheus for metrics.

What it depends on?

  • gorilla/mux for better routing
  • apex/log and apex/httplog for logging
  • caarlos0/env for environment config parsing
  • prometheus/client_golang for prometheus metrics
  • jmoiron/sqlx for improved sql
  • lib/pq as postgresql driver

How is it organized?

$ tree -d .
.
├── config
├── controller
├── datastore
│   └── database
├── migrations
└── model
  • config: contains the config parsing logic;
  • controller: contains the controllers, which usually take an instance of the datasource as parameter;
  • datasource: contains the interfaces that define the access to the database;
  • datasource/database: contains the real implementation of the datasource interfaces;
  • migrations: simple SQL files to setup the database;
  • model: contains the models, which are usually shared accross several packages.

Clonning, installing the dependencies, etc

Golang needs packages to be placed in the right folders inside $GOPATH to work properly:

$ cd $GOPATH
$ mkdir -p src/github.com/caarlos0
$ cd $_
$ git clone git@github.com:caarlos0/go-web-api-example.git
$ cd go-web-api-example

To install all dependencies, just run:

$ make setup

There are several tasks available, try make help

Running locally

1. Create and migrate the database

$ createdb beers
$ for sql in ./migrations/*; do psql ab -f $sql; done

2. Start it up

$ go run main.go

It should be alive at port 3000!

FAQs

Package last updated on 30 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.