Adding Goth to our project

Part 4!

This is part of a series. It is not suited for beginners, but they are welcome too! You can check out the other parts here:

And review how to get up to this part. As always, all the code is at GitHub for part 4.

Today, we’ll add Goth and user Auth0 as our authentication provider to connect users via Google and/or Facebook — or any identity provider using OAuth2.

Adding Goth

Let’s add Goth to our project:

$ go get -u

We can start referencing Goth into our server code, there are a few…

This piece is part of a series. It’s not suited to beginners but you can check it out from the start with part 1

You can review how to get up to this part.

As always, the code is in GitHub.

Today we’ll add GORM and a database to our project. The RDBMS of my choice is PostgreSQL. You can use MySQL, SQLite, whichever you like as long as GORM supports it.

And, you can also check out part 2, in case you’ve missed it. …

In this piece, we’ll add gqlgen’s generated server into our project and start gqling away! And, we are going to move much faster than in part 1.

Adding gqlgen Into the Project

Now, we can use gqlgen to initialize our server’s gqlgen generated files: go run init

This will initialize the gqlgen server. We have to make modifications to fit our project layout, however. Move a couple of files and edit the gqlgen.yml file.

  • generated.go (file that holds the gqlgen's generated GraphQL server code.)

Project setup and initial steps

Let’s make an opinionated GraphQL server using the Gin-gonic web framework, Goth for OAuth2 connections, GORM as DB ORM, and GQLGen for building GraphQL servers.

This project assumes you have at least basic Go knowledge, Go 1.12+ installed, and VSCode (preferred) or similar IDE.

Project Setup

We’ll follow the Go standard project layout for this service. Take a look at the specification. It is opinionated and serves as a good base, though we might stray a little bit from its guidelines.

Start by creating a directory anywhere we want to:

Let’s create the whole project layout with:

internal/gql-server will hold…

Christian Melgarejo

Developer, developer, developer!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store