r/golang Oct 06 '19

Building a Dockerized RESTful API application using Go - microservices

https://medium.com/learning-cloud-native-go/lets-get-it-started-dc4634ef03b
159 Upvotes

11 comments sorted by

23

u/dumindunuwan Oct 06 '19

Hi,

This is the very beginning of this series. As the first step, we are going to discuss about “How to build a Dockerized RESTful API application using Go”.

In this post, we are discussing,

  1. Creating a new Go project.
  2. Adding initial HTTP server.
  3. Adding initial Docker files.
  4. Adding initial configurations.
  5. Adding Chi router.
  6. Adding Zerolog logger.
  7. Adding DB docker file.
  8. Adding initial database migrations.
  9. Adding GORM.
  10. Adding initial books API routes.
  11. Implementing RESTful handlers.
  12. Adding Validator.v9.

The completed project can be found in learning-cloud-native-go/myapp GitHub repository. And I’ll upload the same content to learning-cloud-native-go.github.io which uses Docusaurus in the upcoming days. Hope it will be more structured and easy to see the big picture.

Also, I am not a native English speaker. So, if you found any mistake or something I need to be changed, even a spelling or a grammar mistake, please let me know.

Contribute! 🥤 Buy me a coffee! 🚀 Hire me!

Thanks

1

u/dazzford Oct 07 '19

I think you would better represent the language by skipping 5, 6, and 9.

Do everything with the stdlib and then add those 100% optional and in many cases unnecessary dependencies.

2

u/dumindunuwan Oct 07 '19

The default router is not very powerful. Std log is not a syslogger. GORM, yeah! it's too heavy.

7

u/OursIsTheFury Oct 07 '19

Good stuff, however one remark: for newbies like me it's interesting to get more information on why you make certain choices. For example: you start with creating a go module, but never explain why. Why a module and not just a regular project?

Maybe this is explained later on, but just a thought I had reading the first half.

1

u/dumindunuwan Oct 13 '19

Thanks for highlighting this. I updated both medium post and https://learning-cloud-native-go.github.io/ project. Feel free to inform the places you got confused(even reddit chat is ok). So, I can avoid those confusions from the new readers.

-1

u/aspirTroll Oct 07 '19

Module is the new way to create modules in go which keep record on other dependency modules versions

0

u/dumindunuwan Oct 07 '19

Hi, In Go, a module is a collection of related Go packages that are versioned together as a single unit. Most often, a version control repository contains exactly one module defined in the repository root. Multiple modules are supported in a single repository, but typically that would result in more work on an on-going basis than a single module per repository.

You can find more info in https://github.com/golang/go/wiki/Modules

4

u/leejh3224 Oct 06 '19

Looks awesome! I’ll definitely check it out.

1

u/CountingCats Oct 07 '19

I love how this tutorial includes prompts to go read relevant the documentation as new elements are introduced :)

2

u/dumindunuwan Oct 08 '19

Glad it helped :)

1

u/dazzford Oct 07 '19

You conflate powerful with convenient. The std lib router is more than powerful enough. But you may have to write the url parsing yourself.

But for most microservices, this should be trivial, and would be a good thing to know how to do before taking on the dependency of an external lib.

I have taken dozens of services to production with “just” the std router