kyfk / golang-todo-list-sample

A simple backend application for Todo List apps in written Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

golang-todo-list-sample

A simple backend application for Todo List apps written in Go.

Concept of this repository

Schemaful Generation

I want to suggest to you how to develop a modern backend application written in Go.

My concept is Schemaful Generation, which prevents tired duplicated codes. The DRY principle is one of the essential theories.

The expression of Go is poorer than Ruby, Java, Rust, or other popular programming languages because Go doesn't have functional Generics, Trait, Macro, Enum, or more modern programming language features.

That means you need to write a lot of commonalize lines explicity. Usually, explicity helps you easier than implicitly to debug your application codes, however, that is hard and boring (at least to me). Imagine, if you implement a new REST API endpoint in an application, you may define REST API, then you need to write OpenAPI spec to share with front-side engineers. You may add a path to a server, create a request structure, implement request validation logic... and so on.

You know, everyone wants to focus only on implementing business logic. So I really recommend you generate from schemas. Protocol Buffer is one of those tools.

There's a lot of schema generation libraries using go generate.

I'd like to introduce you how to build a backend application by schema generation using Protocol Buffer(gRPC/protoc-gen-validate/grpc-gateway) and entgo.

Layered Architecture

SOLID principle introduces well-testable and well-maintenable codes.

Layered Architecture is a method that you to follow the principles and gives regularity among your team.

This project inspired by Clean Architecture.

First of all, let me say the name of layers is not matter.

  • Usecase {pkg/usecase}
  • Repository {pkg/repo, pkg/usecase/repo}
  • Presenter {pkg/presenter}

Migration

You need to run MySQL in local environment.

I recoomend to launch that using Docker as below.

docker run -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=true mysql:8 --sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

Then, run the scripts to generate migration file resolving dependencies from previous migration files.

go run ./tools/gen_migration.go {Input migration file name you'd like to be}

About

A simple backend application for Todo List apps in written Go.


Languages

Language:Go 95.5%Language:Shell 4.5%