Skip to content

biergit-ch/go-playground

Repository files navigation

GO Demo REST API

Prerequisite

GO Setup on OSX

GO Setup on Windows

Install Dependencies

$ dep status
$ dep ensure

Setup Environment

This application needs following env variables to use the auth0 authentication.

Environment Value Example
AUTH0_AUDIENCE api identity custom_identity
AUTH0_ISSUER issuer url https://xy.eu.auth0.com/
AUTH0_JWKS keystore json https://../.well-known/jwks.json

Run

$ docker-compose up 
$ go build && ./go-basics

Build & Deploy

Heroku Cloud

Deploy to heroku cloud https://biergit.herokuapp.com

$ make
$ make build
$ cf push -f manifest.yml

Deploy

Pivotal Cloud

Deploy to pivotal cloud https://biergit-api.cfapps.io

$ make
$ make deploy

Layout

  +--------------------------------------------------+   +-----------------+
  |                      api                         |   |     vendor      |
  |--------------------------------------------------|   |-----------------|
  | +---------+  +---------+  +---------+  +-------+ |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | | handler |+>| service |+>|  repo   |+>|  db   | |   |  vendor pkgs    |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | |         |  |         |  |         |  |       | |   |                 |
  | +---------+  +---------+  +---------+  +-------+ |   |                 |
  +--------------------------------------------------+   +-----------------+

Logging

Use this logging mechanism to be indexed by a logging system https://github.com/sirupsen/logrus

import (
	log "github.com/sirupsen/logrus"
)

log.WithFields(log.Fields{
		"key": "value",
	}).Debug("Save user in repository")
	
Result: time="2019-04-08T23:31:03+02:00" level=debug msg="Save user in repository" user_id=0

Swagger

dep ensure -add github.com/go-swagger/go-swagger/cmd/swagger

Use this commenting style to be scanned by swagger generator

// swagger:operation GET /repo/{author} repos repoList
// ---
// summary: List the repositories owned by the given author.
// description: If author length is between 6 and 8, Error Not Found (404) will be returned.
// parameters:
// - name: author
//   in: path
//   description: username of author
//   type: string
//   required: true
// responses:
//   "200":
//     "$ref": "#/responses/reposResp"
//   "404":
//     "$ref": "#/responses/notFound"

Use this commenting style for model

// Description of the Model
// swagger:model User

Use this commenting style for main package

// API REST EXAMPLE
//
// This is a example over how to create the api from the source.
//
//     Schemes: http, https
//     Host: localhost:3000
//     Version: 0.1.0
//     basePath: /api
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
// swagger:meta
package main

Use these commands to generate swagger spec file and serve it

cd cmd/biergit
swagger generate spec -o ../../swagger.json
swagger serve -p 8008 -F redoc ../../swagger.json

Generate GO Docs

run godoc -http=:6060 -v

http://localhost:6060/pkg/git.skydevelopment.ch/zrh-dev/go-basics/

Sources

Basics

Conventions

Layout & Architecture

Interfaces

Persistence

Networking

Json

Error Handling

Configuration

Cloud Foundry

Docs

Best Practices

About

GO play ground project to evaluate the language

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published