[Question] How to split main.go into separate packages/files whilst maintaining Dependency Injection?

This page summarizes the projects mentioned and recommended in the original post on reddit.com/r/golang

Our great sponsors
  • OPS - Build and Run Open Source Unikernels
  • Scout APM - Less time debugging, more time building
  • SonarQube - Static code analysis for 29 languages.
  • GitHub repo krok

    The main server of the hook management system

    Here is a fairly complex project which does just this: https://github.com/krok-o/krok

  • GitHub repo go-structure-examples

    Examples for my talk on structuring go apps

  • OPS

    OPS - Build and Run Open Source Unikernels. Quickly and easily build and deploy open source unikernels in tens of seconds. Deploy in any language to any cloud.

  • GitHub repo svc-fizzbuzz

    A simple fizzbuzz microservice

    For my projects I use this code organization (https://github.com/hugdubois/svc-fizzbuzz). I don't necessarily use dependency injection because I consider go packages to be a singleton (with a setup function).

  • GitHub repo fx

    A dependency injection based application framework for Go. (by uber-go)

    Try fx https://github.com/uber-go/fx. I separate my code into packages in exactly the same way that you want to do and fx takes care of the DI.

  • GitHub repo JSON2App

  • Scout APM

    Less time debugging, more time building. Scout APM allows you to find and fix performance issues with no hassle. Now with error monitoring and external services monitoring, Scout is a developer's best friend when it comes to application development.

  • GitHub repo todo-api-microservice-example

    Go microservice tutorial project using Domain Driven Design and Onion Architecture!

    I maintain an educational repository that describes the approach I've been taking for building proprietary production-ready services for years, it may or may not satisfy what you're asking for but at least it should give you another approach to think about structuring your service.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts