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 (7/19): Connecting with database

So far our backend is working very well. We can create user and login, but as soon we restart our server, that user data is lost, since it is saved only in memory while app is running. Of course that’s not realistic case and we want to save all user data even if server isContinue reading “React Gin Blog (7/19): Connecting with database”

React Gin Blog (6/19): Form validations

As we saw in previous section, our handlers are working as expected when we pass valid data. But what about not valid data? Or missing data? Let’s test this. First, let’s remove (or just comment) Password: passwordValue from our submitHandler() inside of assets/src/components/Auth/AuthForm.js. This way, our backend will send only Username, without Password. Let’s nowContinue reading “React Gin Blog (6/19): Form validations”

React Gin Blog (5/19): Adding user

We are making simple blog, so first thing we have to do is to implement some way for users to create account and log in. For now, we will just make simple struct User that will be stored in memory. Latter we will connect our application with a database so we can store our dataContinue reading “React Gin Blog (5/19): Adding user”

React Gin Blog (4/19): Structure project directories

It’s always good practice to separate your code based on what every part is doing, so it’s easier to find relevant part later on, so we will do just that before going further. In root project directory we will create new directories cmd/rgb/ and we will move our main.go file there. That will be entryContinue reading “React Gin Blog (4/19): Structure project directories”