Skip to content

vonmutinda/crafted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crafted - All about Golang & Microservices

Let's built a ROBUST microservice.

Description

Just for func

    go func(){

    }()

Features

  • RESTful operations
  • DB connection with gorm and RAW SQL usage alongside GORM
  • CLI tooling with Cobra
  • Queues and Messaging with RabbitMQ or Redis.
  • Logging Errors
  • Authentication and Authorization Middlewares
  • CORS with Gorilla Handlers

#TODOs

  • Unit Testing
  • GraphQL APIs
  • gRPC
  • Docker (containerization)
  • CI/CD
  • Grafana and Prometheus Integrations (Later on)

Setup Local

For set up on your machine .

  • Clone the repo git clone https://github.com/vonmutinda/crafted.git.
  • Run go mod init to check if go modules is already initialized.
  • Touch .env file and paste the following configurations.

.env file

    ENV="local"

    PORT=":9000"

    DB_DRIVER="postgres" # <-provide your own-->

    DB_HOST="localhost"

    DB_PORT="5432"

    DB_USER="username" # <-provide your own-->

    DB_NAME="db_name" # <-provide your own-->

    DB_PASS="db_pass" # <-provide your own-->

    API_SECRET="ajsdlfjeo129pusfgan309rudlnlh34ouofOU&)O&UO#jr"  # can you keep a secret?

If you are using a different db from postgres, make sure you import its corresponding dialect in package database

MySQL

package database

import ( 
	"github.com/jinzhu/gorm" 
	_"github.com/jinzhu/gorm/dialects/mysql"
)
// rest of code goes here

Create db and add it's name in .env file. Run go run main.go crafted or go build && ./crafted crafted

Install Docker

Start RabbitMQ container

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

Since we constantly want to listen for any messages hitting the queue, run the cobra command

go run main.go consume

Logging

You realise this application is growing too big and once users begin interacting with it in production, We'll need a way to know where it fails.

Later on we'll configure our logger and other parts of our app with Prometheus are Grafana.

Technologies Used

Here's a list of technologies used in this project

NOTES:

  • Use Sentence case when naming funcs intended for global usage.
  • Receivers must be pointers.
  • Channels are used when Feedback is expected from a go routine
  • Waitgroups are used when we don't care about Feedback. We only want the job done.
  • A WaitGroup is of type sync.WaitGroup but we use a pointer of that type in a go routine.

Resources

Below are helpful resources on where to read more about Go/Golang.

About

Building Microservices in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published