Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

Package Overview
Dependencies
Alerts
File Explorer
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
  • Source
  • Go
  • Socket score

Version published
Created
Source

Go Report Card Go Doc Release

go-standard-layout

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

  1. Root package is for domain types
  2. Group subpackages by dependency
  3. Make dependencies explicit!
  4. Main package ties together dependencies
  5. Loggers are dependencies!
  6. Use the “underscore test” package
  7. Use a shared mock subpackage
  8. Using table-driven-test style for testing
  9. Provide database integration test
  10. testdata folder name for containing test fixtures
  11. Go interfaces generally belong in the package that uses values of the interface type, not the package that implements those values
  12. 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

  1. https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1
  2. https://peter.bourgon.org/go-best-practices-2016
  3. https://medium.com/@benbjohnson/structuring-tests-in-go-46ddee7a25c
  4. https://www.youtube.com/watch?v=yszygk1cpEc
  5. https://dave.cheney.net/2016/05/10/test-fixtures-in-go
  6. https://github.com/golang/go/wiki/CodeReviewComments#interfaces

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc