React Gin Blog (19/19): Docker deploy

Our server is finished and almost ready for deploy, which will be done using Docker. Notice that i said it’s almost ready, so let’s see what is missing. This whole time we used React development server which is listening on port 3000 and redirecting all requests to our backend on port 8080. That makes senseContinue reading “React Gin Blog (19/19): Docker deploy”

React Gin Blog (18/19): Tests

Writing unit and integration tests is important part of software development and it’s something ideally done during development, but in this guide i dedicated one chapter for that since there are some prerequisites required before we can start to write tests. For instance, main thing to do is to create test database. This will beContinue reading “React Gin Blog (18/19): Tests”

React Gin Blog (17/19): Graceful shutdown

If our server process gets signal to shut it down, we would like to finish the request currently handling before that happens. For that we will use graceful shutdown provided by Gin. This example is explained in detail on Gin GitHub with description in comments, so i will not go into details myself. Our internal/server/server.goContinue reading “React Gin Blog (17/19): Graceful shutdown”

React Gin Blog (16/19): Custom database errors

Custom validation errors are added in previous chapter, but what about database errors? If you try to create account with already existing username, you will get error ERROR #23505 duplicate key value violates unique constraint “users_username_key”. Unfortunately, there is no validator involved here and pg module returns most of the errors as map[byte]string so thisContinue reading “React Gin Blog (16/19): Custom database errors”

React Gin Blog (15/19): Custom validation errors

If you try to create new account using too short password, you will get error Key: ‘User.Password’ Error:Field validation for ‘Password’ failed on the ‘min’ tag. This is not really user friendly, so it should be changed for better user experience. Let’s see how we can transform that to our own custom error messages. ForContinue reading “React Gin Blog (15/19): Custom validation errors”

React Gin Blog (14/19): Add user posts

With authentication in place, it is time to start using it. We will need authentication to create, read, update and delete user’s blog posts. Let’s start by adding new database migration which will create required data table with columns. Create new migration file migrations/2_addPostsTable.go: And then run migrations with: Now we create structure to holdContinue reading “React Gin Blog (14/19): Add user posts”

React Gin Blog (13/19): JWT authentication

Authentication is one of the most important part of almost every web application. We must ensure that every user can create, read, update and delete only data for which it’s authorized. For that purpose we will use JWT (JSON Web Token). Fortunately, there are various Golang modules specialized for this. One that will be usedContinue reading “React Gin Blog (13/19): JWT authentication”

React Gin Blog (12/19): Logging

Logging is also pretty important part of most web applications because we usually want to know what requests are coming in, and what’s more important, whether there are any unexpected errors. So, as you may have guessed, this section will introduce logging and i will show you how to setup logging, and how to separateContinue reading “React Gin Blog (12/19): Logging”

React Gin Blog (11/19): Deploy and stop scripts

Now that we moved our configuration to ENV, we need to source .env every time we restart our machine or shell session, which can become a bit tedious. To make our lives easier, we will create bash scripts for starting and stopping server. While at it, we will also separate deploy for dev and prodContinue reading “React Gin Blog (11/19): Deploy and stop scripts”

React Gin Blog (10/19): Server configuration

Currently we have hardcoded values for server address and port. Same goes for database options required for connecting to our database. That is obviously not a great solution, so let’s extract this configuration to ENV variables and add logic to read values from there. First we will create new directory internal/conf/ and there we willContinue reading “React Gin Blog (10/19): Server configuration”