Giter Club home page Giter Club logo

example-java's Introduction

example-java

Java, Spring Boot, GraphQL and Resful, Auth with JWT and much more.

Endpoints

Endpoint Method Action
/graphql POST
/graphiql GET
/users GET Index
/users POST Store
/users PATCH Update
/users/:id DELETE Destroy
/users/:id GET Show

Insomnia

If you use Insomnia, just import a insomnia-v4.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 Started 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 db-postgres.yml up

Open your debug on VScode and run "Launch file"

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

All steps necessary to make this example project.

Create a mod init

All libs in Golang have a module name. This is for a package manage for Golang, like a npm/yarm for nodeJS, gradlew/mavem for Java, compose for PHP, mix for Elixir and many more.

go mod init github.com/ruyjfs/example-golang

See: go.mod

Create a file main.go - The Hello World

 echo '' >> main.go
package main

import (
	"log"
)

func main() {
	log.Printf("Hello World!")
}

Run to see you first hello world

go run main.go

Install Gin Framework

go get github.com/codegangsta/gin

Update a file 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 GraphQL

go run github.com/99designs/gqlgen init

To generate graphql files.

gqlgen generate

On docker

~/go/bin/gqlgen generate

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

Run Debugg

With VScode and SGBD on Docker

docker-compose -f db-postgres.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

Technologies:

References

example-java's People

Contributors

ruyjfs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.