🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

github.com/hendra-huang/go-standard-layout

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hendra-huang/go-standard-layout

v0.0.0-20180925033700-06ea2b7fe77a
Version published
Created

Go Report Card Go Doc Release

go-standard-layout

Reading some articles for designing go standard layout. These are the guidelines that I use:

  • Root package is for domain types
  • Group subpackages by dependency
  • Make dependencies explicit!
  • Main package ties together dependencies
  • Loggers are dependencies!
  • Use the “underscore test” package
  • Use a shared mock subpackage
  • Using table-driven-test style for testing
  • Provide database integration test
  • testdata folder name for containing test fixtures
  • Go interfaces generally belong in the package that uses values of the interface type, not the package that implements those values
  • The implementing package should return concrete (usually pointer or struct) types

About the project

This is a small app that consist of 2 entities, User and Article. 1 user can have more than 1 articles. For both entities, there are some sample endpoints provided. I wrap the router and provides basic monitoring using prometheus. I use dep for depedency management. There is simple opentracing implementation in this app. This app is also provided with unit test and parallel database integration test.

About the structure

The files in the root package contains domain logic (business logic) of the app. cmd contains entrypoint of the app / command. script contains shell script that can help to automate the build process, etc. Currently, script contains script for running test with code coverage preview. The rest of folders are the dependencies of the app. The data layer is at mysql package. You can find list of endpoints in router package. HTTP handler is located in handler package inside server folder.

References

FAQs

Package last updated on 25 Sep 2018

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