Skip to content

ruyjfs/lab-bank-go

Repository files navigation

The Bank

A example of bank transaction, made with GOlang, Gin Framework, Restful and GraphQL.

Endpoints

Endpoint Method Action
/graphql POST
/graphiql GET
/accounts GET Index
/accounts POST Store
/accounts PATCH Update
/accounts/:id DELETE Destroy
/accounts/:id GET Show
/transactions GET Index
/transactions POST Store
/transactions PATCH Update
/transactions/:id DELETE Destroy
/transactions/:id GET Show
/operations-types GET Index
/operations-types POST Store
/operations-types PATCH Update
/operations-types/:id DELETE Destroy
/operations-types/:id GET Show

Insomnia

If you use Insomnia, just import a insomnia.yaml

Get Started

Just one command

docker-compose up --build

Open on you best browser: http://localhost:8085
GraphQL Playground: http://localhost:8085/gaphiql
To see a database open adminer on: http://localhost:8086
Configurations for connect on database see: /docker/local.env IMPORTANT! If you not have a docker see: Get Started - without docker

Structure

├── config - (configuration)
├── controllers (RESTfull methods)
├── core (Base methos for controllers, models and services)
├── database - (database configuration, migrate and seed data)
├── graphql
│   ├── generated            - A package that only contains the generated runtime
│   │   └── generated.go
│   ├── model                - A package for all your graph models, generated or otherwise
│   │   └── models_gen.go
│   ├── resolver.go          - The root graph resolver type. This file wont get regenerated
│   ├── schema.graphqls      - Some schema. You can split the schema into as many graphql files as you like
│   └── schema.resolvers.go  - the resolver implementation for schema.graphql
├── models (ORM models based on Database tables)
├── routes (files with routes)
├── services (with business rules and intermediate a database)controlling the generated code.
├── go.mod
├── go.sum
├── gqlgen.yml               - The gqlgen config file, knobs for
└── main.go                  - The entry point to your app. Customize it however you see fit

Commands

Enter on docker container to exec any command.

docker exec -it labbankgo-api /bin/bash

To generate graphql files.

gqlgen generate

On docker

~/go/bin/gqlgen generate

Out of docker

Get Stared without docker

A Database PostgreSQL is needed, configurations for it in docker/local.env

gin --port=8080 #or ~/go/bin/gin --port=8080

Run Debugg

With VScode and SGBD on Docker

docker-compose -f docker-compose-db.yml up

Unity Test and Test Integration

go test -v ./src/tests/

With code coverage

go test -cover -coverprofile=c.out ./src/tests/
go tool cover -html=c.out -o coverage.html

Step By Step (for create this project)

Create a mod file for dependence management

go mod init github.com/ruyjfs/lab-bank-go

Install Gin Framework

go get github.com/codegangsta/gin

Create a main.go with this example code

package main

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func setupRouter() *gin.Engine {
	r := gin.Default()

	r.GET("/:name", func(c *gin.Context) {
		name := c.Params.ByName("name")
		c.String(http.StatusOK, "Hello World", name)
	})

	return r
}

func main() {
	r := setupRouter()
	r.Run(":8080")
}

Install GQLgen for GraphQL

go get github.com/99designs/gqlgen

Initial structure for GraphQL

go run github.com/99designs/gqlgen init

Install GORM

go get -u gorm.io/gorm && \
go get -u gorm.io/driver/postgres

Start project with Hot Reload

~/go/bin/gin

Default start project

go run main.go

Open on you best browser: http://localhost:8085

Technologies:

References

About

A Bank transaction made with GOlang and Gin Framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published