7

So I'm in the process of learning go for building RESTful microservices and I have a really stupid but simple question.
Does a go microservice need more than one file? I ask this because my day job is c# and for those who know, asp.net rest projects have a lot of files

Comments
  • 3
    I think its the same as with C#. Its possible to do it in a single file but everyone prefers multiple files
  • 1
    @Codex404 I figured as much. It's just such a different way of working
  • 2
    @Darkovernerd I understand, Im also a .net dev and tried go twice.
  • 1
    @Codex404 I love how fast go is to write and compile and how simple it is. I guess the obvious it to have a file for database handling, one for serialisation, one for what are essentially controllers
  • 2
    No project "needs" to be all in a single file, and that goes for microservices too. Microservices usually have a bunch of boilerplate setup code (initialise DB connections, initialise connections to other services, initialise logging, check feature flags, start webserver) etc which has nothing to do with your application logic and is best stored separately.

    Depending on how "micro" your microservice is, it might have a couple of separate concepts within it which are more maintainable when represented in separate files. Some languages such as Java even enforce one top-level class per file.

    Put more simply - would you rather deal with finding where abouts in a ~30,000 line file to make a change, or would you rather the functionality is divided up into logical components and split amongst multiple small files, with each filename describing what's in the file?
  • 0
    @unsignedint that's really helpful, thank you. I guess it's simply enforcing the separation of concerns
Your Job Suck?
Get a Better Job
Add Comment