|
| 1 | +## CodelyTV - Go HTTP API - Hexagonal Architecture |
| 2 | + |
| 3 | +This repository contains the code examples used on the CodelyTV course. |
| 4 | + |
| 5 | +### Requirements |
| 6 | + |
| 7 | +- Go v1.15+ |
| 8 | +- MySQL (see below). |
| 9 | + |
| 10 | +### Contents |
| 11 | + |
| 12 | +This project has been designed as a single Go module with multiple applications. |
| 13 | +Each folder contains a completely functional application (binary) that can be executed isolated. |
| 14 | + |
| 15 | +Each folder corresponds to one of the course lessons / videos: |
| 16 | +1. [`01-01-your-first-http-endpoint`](./01-01-your-first-http-endpoint) - Nuestro primer endpoint HTTP en Go |
| 17 | +1. [`01-02-using-gin`](./01-02-using-gin) - Usando Gin: nuestro primer framework |
| 18 | +1. [`01-03-architectured-healthcheck`](./01-03-architectured-healthcheck) - Arquitecturando nuestro health check |
| 19 | +1. [`02-01-post-course-endpoint`](./02-01-post-course-endpoint) - Implementando el endpoint de creación de curso |
| 20 | +1. [`02-02-repository-injection`](./02-02-repository-injection) - Inyectando nuestro repositorio |
| 21 | +1. [`02-03-controller-test`](./02-03-controller-test) - Testeando nuestro endpoint |
| 22 | +1. [`02-04-domain-validations`](./02-04-domain-validations) - Añadiendo validaciones a nuestro dominio |
| 23 | +1. [`03-01-mysql-repository-implementation`](./03-01-mysql-repository-implementation) - Implementando nuestro repositorio para MySQL |
| 24 | +1. [`03-02-repository-test`](./03-02-repository-test) - Testeando nuestro repositorio |
| 25 | + |
| 26 | +### Usage |
| 27 | + |
| 28 | +To execute the application from any lesson, just run: |
| 29 | + |
| 30 | +```sh |
| 31 | +export COURSE_LESSON=02-04-domain-validations; go run $COURSE_LESSON/cmd/api/main.go |
| 32 | +``` |
| 33 | + |
| 34 | +Replacing `COURSE_LESSON` value by any of the available ones. |
| 35 | + |
| 36 | +#### Simple examples |
| 37 | + |
| 38 | +Some lessons only contain a single `main.go` file with a few lines of code. |
| 39 | +To run one of those lessons, just run: |
| 40 | + |
| 41 | +```sh |
| 42 | +export COURSE_LESSON=01-01-your-first-http-endpoint; go run $COURSE_LESSON/main.go |
| 43 | +``` |
| 44 | + |
| 45 | +#### MySQL & Docker |
| 46 | + |
| 47 | +From `02-01-post-course-endpoint` on, the application on each directory relies |
| 48 | +on a MySQL database. So, to simplify its execution, we've added a |
| 49 | +`docker-compose.yaml` file with a MySQL container already set up. |
| 50 | + |
| 51 | +To run it, just execute: |
| 52 | + |
| 53 | +```sh |
| 54 | +docker-compose up -d |
| 55 | +``` |
| 56 | + |
| 57 | +You can also use your own MySQL instance. Note that those applications |
| 58 | +expects a MySQL instance to be available on `localhost:3306`, |
| 59 | +identified by `codely:codely` and with a `codely` database. |
| 60 | + |
| 61 | +To set up your database, you can execute the `schema.sql` file |
| 62 | +present on the `sql` directory. It's automatically loaded if |
| 63 | +you use the provided `docker-compose.yaml` file. |
| 64 | + |
| 65 | +#### Tests |
| 66 | + |
| 67 | +To execute all tests, just run: |
| 68 | + |
| 69 | +```sh |
| 70 | +go test ./... |
| 71 | +``` |
| 72 | + |
| 73 | +To execute only the tests present in one of the lessons, run: |
| 74 | + |
| 75 | +```sh |
| 76 | +go test ./02-04-domain-validations/... |
| 77 | +``` |
0 commit comments