golang-api-skeleton

command module
v0.0.0-...-7fe122b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2018 License: GPL-3.0 Imports: 11 Imported by: 0

README

Golang Skeleton API

This is a project to help you get up an running fast with a secure, light weight, extensible api structure.

Skill level

Intermediate This project gives you a basic structure to work with.

Prerequisites:
  • Docker
  • Secret Key Generation and handling (for JWT's)
  • MySQL

Features

  • Built in load balancer
  • MC (MVC with out the view) esc structure
  • Request logging to NoSql DynamoDB
  • JWT Generation for user authentication

Application Structure

Routing & Request workflow:

Routing in the API takes a slightly different approach from an MVC architecture. Step by step:

  1. Initial Request: Request comes in and a handler is found that maps to the base request. See main.go's routes.
  2. Handlers: The handler registers it's own routes and passes them to a routing function that parses the path and determines which callback function to call.
  3. Handler Functions: The called handler function instantiates the proper record and calls the associated functions and returns the resulting response.
  4. Records: A Record is a representation of a database table in the form a struct. It holds all the necessary Queries.
  5. Connection: A connection is a connection to a data source.

Other Things

Request Logging

The api is set up to log requests to a dynamodb on AWS. You must supply the proper credentails for the api to connect to the service. See amazons credential documentation. You can comment out where the log is pushed to the log channel in the RouteController function in the handler.go file if you want to disable logging.

Creating a super secret key

If you need to generate a key for your server: run the script in the templates folder in the docker folder, that will generate a byte key that will then be copied to the docker container and be used for generating jwt's and hashing passwords.

Verbose

Verbose can be turned off in the Dockerfile under API_VERBOSE. Verbose will print err's and stack traces when set in the api response.

External libraries

SHA3

Contributing

Feel free to open any and all pull requests. :D

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL