[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 /r/golang

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • 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

  • go-structure-examples

    Examples for my talk on structuring go apps

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • 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).

  • 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.

  • JSON2App

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • 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