Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Full-Stack Web Development with Go
Full-Stack Web Development with Go

Full-Stack Web Development with Go: Build your web applications quickly using the Go programming language and Vue.js

eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Full-Stack Web Development with Go

Building the Database and Model

In this chapter, we will design the database that our sample application will use. We will walk through the design of the database and look at some of the tools that we are going to use to help us on our database design journey. We will be using the Postgres database and will look at how to run it locally using Docker. What is Docker? In simple terms, Docker is a tool that allows developers to run a variety of applications such as the database, the HTTP server, system tools, and so on – locally or in the cloud. Docker removes the need to install all the different dependencies required to use a particular application such as a database, and it makes it easier to manage and maintain applications than installing on bare metal in both local and cloud environments. This is possible using Docker because it packages everything into a single file similar to how a compressed file contains different files internally.

We will learn how to design a database that supports the features that we want to build, such as the following:

  • Creating an exercise
  • Creating a workout plan
  • Logging in to the system

We will also explore tools that will help in automatic code generation based on SQL queries, which reduces the amount of database-related code that needs to be written to a large extent. Readers will learn to use the tool to also auto-generate all the relevant CRUD operations without writing a single line of Go code.

In this chapter, we’ll be covering the following:

  • Installing Docker
  • Setting up Postgres
  • Designing the database
  • Installing sqlc
  • Using sqlc
  • Setting up the database
  • Generating CRUD with sqlc
  • Building the makefile

Technical requirements

In this book, we will be using version 1.16 of the Go programming language, but you are free to use later versions of Go, as the code will work without any changes. To make it easy, all the relevant files explained in this chapter can be checked out at https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Go/tree/main/Chapter01. To work on the sample code in this chapter, make sure you change the directory to Chapter 1Full-Stack-Web-Development-with-Go/chapter1. If you are using Windows as a development machine, use WSL2 to perform all the different operations explained in this chapter.

Installing Docker

In this book, we will be using Docker to do things such as running databases and executing database tools, among others. You can install either Docker Desktop or Docker Engine. To understand more about the difference between Docker Desktop and Engine, visit the following link: https://docs.docker.com/desktop/linux/install/#differences-between-docker-desktop-for-linux-and-docker-engine. The authors use Docker Engine in Linux and Docker Desktop for Mac.

If you are installing Docker Desktop on your local machine, the following are the links for the different operating systems:

If you want to install Docker binaries, you can follow the following guide: https://docs.docker.com/engine/install/binaries/.

Setting up Postgres

The database we chose for the sample application is Postgres; we chose Postgres over other databases because of the wide variety of open source tools available for building, configuring, and maintaining Postgres. Postgres has been open source from version 1 since 1989 and it is used by big tech startups worldwide. The project has a lot of community support in terms of tools and utilities, which makes it easier to manage and maintain. The database is suitable for small all the way to big replicated data stores.

The easiest way to run it locally is to run it as a Docker container. First, use the following command to run Postgres:

docker run --name test-postgres \
-e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 -d postgres

The command will run postgres on port 5432; if by any chance you have other applications or other Postgres instances listening to this port, the command will fail. If you need to run Postgres on a different port, change the -p parameter (for example, -p 5555:5432) to a different port number.

If successful, you will see the container ID printed out. The ID will differ from what is shown here:

f7bdfb7d2c10c5f0c9227c9b0a720f21d3c7fa65907eb0c546b8f20f12621102

Check whether Postgres is up and running by using docker ps. The next thing to do is use the psql-client tool to connect to Postgres to test it out. A list of the different Postgres client tools available on different platforms can be found here: https://wiki.postgresql.org/wiki/PostgreSQL_Clients.

We will use the standard postgres psql tool using Docker. Open another terminal and use the following Docker command to run psql:

docker exec -it test-postgres psql -h localhost -p 5432 -U postgres -d postgres

What we are doing is executing the psql command inside the running Postgres container. You will see output such as the following, indicating that it has successfully connected to the Postgres database:

psql (12.3, server 14.5 (Debian 14.5-1.pgdg110+1))
WARNING: psql major version 12, server major version 14.
         Some psql features might not work.
Type "help" for help.
postgres=#

On a successful connection, you will see the following output. Note that the warning message mentions server major version 14 – this is to indicate that the server version is newer than the current psql version as per the documentation (https://www.postgresql.org/docs/12/app-psql.html). The psql client will work without any problem with the Postgres server:

psql (12.3, server 14.0 (Debian 14.0-1.pgdg110+1))
WARNING: psql major version 12, server major version 14.
         Some psql features might not work.
Type "help" for help.
postgres=#

Exit psql to go back to the command prompt by typing exit.

The following is some guidance on common errors when trying to connect to the database:

Error Message

Description

psql: error: could not connect to server: FATAL: password authentication failed for user “postgres”

The password specified when running Postgres does not match with the password passed in using psql. Check the password.

psql: error: could not connect to server: could not connect to server: Host is unreachable

The IP address that you use to connect to Postgres is wrong.

With this, you have completed the local setup of Postgres and are now ready to start looking into designing the database.

Designing the database

In this section, we will look at how to design the database to allow us to store information for the fitness tracking application. The following screenshot shows a mockup of the application:

Figure 1.1 – Screenshot of the sample application

Figure 1.1 – Screenshot of the sample application

Looking at these functionalities, we will look at designing a database structure that will look like the following entity relationship diagram:

Entity relationship diagram

An entity relationship diagram shows the relationships of entity sets stored in a database.

Figure 1.2 – Entity relationship diagram of our fitness application

Figure 1.2 – Entity relationship diagram of our fitness application

Let’s drill further into each table to understand the data that they contain:

Table Name

Description

Users

This table contains user information for login purposes. Passwords will be stored as a hash, not plaintext.

Images

This table contains images of exercises that users want to do. This table will store all the exercise images that the user uploads.

Exercises

This table contains the name of the exercise that the user wants to do. Users will define what kind of exercise they want to do.

Sets

This table contains the number of sets of each exercise that the user wants to do.

Workouts

This table contains the workouts that the user wants to do. Users define a workout as a combination of exercises with the number of sets that they want to do.

The trade-off we are making to store images in the database is to simplify the design; in reality, this might not be suitable for bigger images and production. Now that we have defined the database structure and understand what kind of data it will store, we need to look at how to implement it. One of the major criteria that we want to focus on is to completely separate writing SQL from the code; this way, we have a clear separation between the two, which will allow higher maintainability.

Installing sqlc

We have defined the database structure so now it’s time to talk a bit more about the tool that we are going to be using called sqlc. sqlc is an open source tool that generates type-safe code from SQL; this allows developers to focus on writing SQL and leave the Go code to sqlc. This reduces the development time, as sqlc takes care of the mundane coding of queries and types.

The tool is available at https://github.com/kyleconroy/sqlc. The tool helps developers focus on writing the SQL code that is needed for the application and it will generate all the relevant code needed for the application. This way, developers will be using pure Go code for database operations. The separation is clean and easily trackable.

The following diagram shows the flow that developers normally adopt when using the tool at a high level.

Figure 1.3 – Flow to use sqlc to generate Go code

Figure 1.3 – Flow to use sqlc to generate Go code

All SQL code will be written in .sql files, which will be read and converted by the sqlc tool into the different Go code.

Download and install SQL binary by using the following command:

go install github.com/kyleconroy/sqlc/cmd/sqlc@latest

Make sure your path includes the GOPATH/bin directory – for example, in our case, our path looks like the following:

…:/snap/bin:/home/nanik/goroot/go1.16.15/go/bin:/home/nanik/go/bin

If you don’t have GOPATH as part of the PATH environment variable, then you can use the following command to run sqlc:

$GOPATH/bin/sqlc
Usage:
  sqlc [command]
Available Commands:
  compile     Statically check SQL for syntax and type
  errors
  completion  Generate the autocompletion script for the
  specified shell
  generate    Generate Go code from SQL
  help        Help about any command
  init        Create an empty sqlc.yaml settings file
  upload      Upload the schema, queries, and configuration
  for this project
  version     Print the sqlc version number
Flags:
  -x, --experimental   enable experimental features (default: false)
  -f, --file string    specify an alternate config file (default: sqlc.yaml)
  -h, --help           help for sqlc

Use "sqlc [command] --help" for more information about a command.

At the time of writing, the latest version of sqlc is v1.13.0.

Now that we have installed the tool and understand the development workflow that we will be following when using the tool, we will look at how to use the tool for our application.

Using sqlc

First, let’s take a look at the different commands provided by sqlc and how they work.

Commands

Explanation

compile

This command helps check SQL syntax and reports any typing errors.

completion

This command is to generate an auto-completion script for your environment. The following are the supported environments: Bash, Fish, PowerShell, and zsh.

generate

A command to generate the .go files based on the provided SQL statements. This will be the command that we will be using a lot for the application.

init

This command is the first command that is used to initialize your application to start using this tool.

The following will show how to get started with using sqlc to set up a project. Create a directory inside chapter1 – for example, dbtest – and change the directory to the new directory (dbtest). Next, we will run sqlc with the init command:

sqlc init

This will automatically generate a file called sqlc.yaml, which contains a blank configuration as shown here:

version: "1"
project:
    id: ""
packages: []

The sqlc.yaml contains configuration information that sqlc will use to generate all the relevant .go code for our SQL statements.

Let’s take a look at the structure of the .yaml file to understand the different properties. The following shows an example of a completed structure:

version: "1"
packages:
 - name: "db"
   path: "db"
   queries: "./sqlquery"
   schema: "./sqlquery/schema/"
   engine: "postgresql"
   sql_engine: "database/sql"
   emit_db_tags: "true"
   emit_prepared_queries: true
   emit_interface: false
   emit_exact_table_names: false
   emit_empty_slices: false
   emit_exported_queries: false
   emit_json_tags: true
   json_tags_case_style: "snake"
   output_db_file_name: "db.go"
   output_models_file_name: "dbmodels.go"
   output_querier_file_name: "dbquerier.go"
   output_files_suffix: "_gen"

The following table explains the different fields:

Tag Name

Description

Name

Any string to be used as the package name.

Path

Specifies the name of the directory that will host the generated .go code.

Queries

Specifies the directory name containing the SQL queries that sqlc will use to generate the .go code.

Schema

A directory containing SQL files that will be used to generate all the relevant .go files.

Engine

Specifies the database engine that will be used: sqlc supports either MySQL or Postgres.

emit_db_tags

Setting this to true will generate the struct with db tags – for example:

type ExerciseTable struct {

ExerciseID int64 `db:"exercise_id"

ExerciseName string `db:"exercise_name"

}

emit_prepared_queries

Setting this to true instructs sqlc to support prepared queries in the generated code.

emit_interface

Setting this to true will instruct sqlc to generate the querier interface.

emit_exact_table_names

Setting this to true will instruct sqlc to mirror the struct name to the table name.

emit_empty_slices

Setting this to true will instruct sqlc to return an empty slice for returning data on many sides of the table.

emit_exported_queries

Setting this to true will instruct sqlc to allow the SQL statement used in the auto-generated code to be accessed by an outside package.

emit_json_tags

Setting this to true will generate the struct with JSON tags.

json_tags_case_style

This setting can accept the following – camel, pascal, snake, and none. The case style is used for the JSON tags used in the struct. Normally, this is used with emit_json_tags.

output_db_file_name

Name used as the filename for the auto-generated database file.

output_models_file_name

Name used as the filename for the auto-generated model file.

output_querier_file_name

Name used as the filename for the auto-generated querier file.

output_files_suffix

Suffix to be used as part of the auto-generated query file.

We have looked at the different parameters available in the tool, along with how to use the .yaml file to specify the different properties used to generate the relevant Go files. In the next section, we will set up our sample app database.

Setting up the database

We need to prepare and create the database using the psql client tool. The SQL database script can be found inside schema.sql under the db folder in the GitHub repository, and we are going to use this to create all the relevant tables inside Postgres.

Change the directory to chapter1 and run the Postgres database using the following Docker command:

docker run --name test-postgres -e POSTGRES_PASSWORD=mysecretpassword -v $(pwd):/usr/share/chapter1 -p 5432:5432 postgres

Once postgres is running, use the following command to enter into psql:

docker exec -it test-postgres psql -h localhost -p 5432 -U postgres -d postgres

Once inside the psql command, run the following:

\i /usr/share/chapter1/db/schema.sql

This will instruct psql to execute the commands inside schema.sql, and on completion, you will see the following output:

postgres=# \i /usr/share/chapter1/db/schema.sql
CREATE SCHEMA
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE

To reconfirm that everything is set up correctly, use the following command (do not forget to include the dot after gowebapp):

\dt gowebapp.* 

You should see the following output:

postgres=# \dt gowebapp.*
            List of relations
  Schema  |   Name    | Type  |  Owner
----------+-----------+-------+----------
 gowebapp | exercises | table | postgres
 gowebapp | images    | table | postgres
 gowebapp | sets      | table | postgres
 gowebapp | users     | table | postgres
 gowebapp | workouts  | table | postgres
(5 rows)

Now that we have completed setting up our database, we are ready to move to the next section, where we will be setting up sqlc to generate the Go files.

Generating CRUD with sqlc

CRUD stands for Create, Read, Update, and Delete, which refers to all the major functions that are inherent to relational databases. In this section, we will do the following for the application:

  • Complete the sqlc configuration file
  • Create SQL query files

Once done, we will be able to autogenerate the different files required to allow us to perform CRUD operations to the database from the application. First, open sqlc.yaml and enter the following configuration:

---
version: '1'
packages:
 - name: chapter1
   path: gen
   schema: db/
   queries: queries/
   engine: postgresql
   emit_db_tags: true
   emit_interface: false
   emit_exact_table_names: false
   emit_empty_slices: false
   emit_exported_queries: false
   emit_json_tags: true
   json_tags_case_style: camel
   output_files_suffix: _gen
   emit_prepared_queries: false

Our application is now complete with all that we need for the database, and sqlc will autogenerate the .go files. The following is how the application directory and files will look:

.
├── db
│   └── schema.sql
├── go.mod
├── queries
│   └── query.sql
└── sqlc.yaml

We can run sqlc to generate the .go files using the following command:

sqlc generate 

By default, sqlc will look for the sqlc.yaml file. If the filename is different, you can specify it using the -f flag as follows:

sqlc generate -f sqlc.yaml 

Once the operation completes, there will be no output; however, a new directory called gen will be generated as shown here:

./gen/
├── db.go
├── models.go
└── query.sql_gen.go

We have completed the auto-generation process using sqlc; now, let’s take a look at the schema and queries that sqlc uses to generate the code.

The following is a snippet of the schema.sql file that is used by sqlc to understand the structure of the database:

CREATE SCHEMA IF NOT EXISTS gowebapp;
CREATE TABLE gowebapp.users (
User_ID        BIGSERIAL PRIMARY KEY,
User_Name      text NOT NULL,
....
);
....
CREATE TABLE gowebapp.sets (
Set_ID      BIGSERIAL PRIMARY KEY,
Exercise_ID BIGINT NOT NULL,
Weight      INT NOT NULL DEFAULT 0
);

The other file sqlc uses is the query file. The query file contains all the relevant queries that will perform CRUD operations based on the database structure given here. The following is a snippet of the query.sql file:

-- name: ListUsers :many
-- get all users ordered by the username
SELECT *
FROM gowebapp.users
ORDER BY user_name;
...
-- name: DeleteUserImage :exec
-- delete a particular user's image
DELETE
FROM gowebapp.images i
WHERE i.user_id = $1;
...
-- name: UpsertExercise :one
-- insert or update exercise of a particular id
INSERT INTO gowebapp.exercises (Exercise_Name)
VALUES ($1) ON CONFLICT (Exercise_ID) DO
UPDATE
    SET Exercise_Name = EXCLUDED.Exercise_Name
    RETURNING Exercise_ID;
-- name: CreateUserImage :one
-- insert a new image
INSERT INTO gowebapp.images (User_ID, Content_Type,
                             Image_Data)
values ($1,
        $2,
        $3) RETURNING *;
...

Using query.sql and schema.sql, sqlc will automatically generate all the relevant .go files, combining information for these two files together and allowing the application to perform CRUD operations to the database by accessing it like a normal struct object in Go.

The last piece that we want to take a look at is the generated Go files. As shown previously, there are three auto-generated files inside the gen folders: db.go, models.go, and query.sql_gen.go.

Let’s take a look at each one of them to understand what they contain and how they will be used in our application:

  • db.go:

This file contains an interface that will be used by the other auto-generated files to make SQL calls to the database. It also contains functions to create a Go struct that is used to do CRUD operations.

A new function is used to create a query struct, passing in a DBTX struct. The DBTX struct implementation is either sql.DB or sql.Conn.

The WithTx function is used to wrap the Queries object in a database transaction; this is useful in situations where there could be an update operation on multiple tables that need to be committed in a single database transaction:

func New(db DBTX) *Queries {
  return &Queries{db: db}
}
func (q *Queries) WithTx(tx *sql.Tx) *Queries {
  return &Queries{
    db: tx,
  }
}
  • models.go:

This file contains the struct of the tables in the database:

type GowebappExercise struct {
  ExerciseID   int64  `db:"exercise_id"
    json:"exerciseID"`
  ExerciseName string `db:"exercise_name"
    json:"exerciseName"`
}
...
type GowebappWorkout struct {
  WorkoutID int64     `db:"workout_id"
    json:"workoutID"`
  UserID    int64     `db:"user_id" json:"userID"`
  SetID     int64     `db:"set_id" json:"setID"`
  StartDate time.Time `db:"start_date"
    json:"startDate"`
}
  • query.sql_gen.go:

This file contains CRUD functions for the database, along with the different parameters struct that can be used to perform the operation:

const deleteUsers = `-- name: DeleteUsers :exec
DELETE FROM gowebapp.users
WHERE user_id = $1
`
func (q *Queries) DeleteUsers(ctx context.Context,
userID int64) error {
  _, err := q.db.ExecContext(ctx, deleteUsers, userID)
  return err
}
...
const getUsers = `-- name: GetUsers :one
SELECT user_id, user_name, pass_word_hash, name, config, created_at, is_enabled FROM gowebapp.users
WHERE user_id = $1 LIMIT 1
`
func (q *Queries) GetUsers(ctx context.Context, userID int64) (GowebappUser, error) {
  row := q.db.QueryRowContext(ctx, getUsers, userID)
  var i GowebappUser
  err := row.Scan(
           &i.UserID,
           &i.UserName,
           &i.PassWordHash,
           &i.Name,
           &i.Config,
           &i.CreatedAt,
           &i.IsEnabled,
  )
  return i, err
}
...

Now that the database and auto-generated data to perform CRUD operations are complete, let’s try all this by doing a simple insert operation into the user table.

The following is a snippet of main.go:

package main
import (
  ...
)
func main() {
  ...
  // Open the database
  db, err := sql.Open("postgres", dbURI)
  if err != nil {
    panic(err)
  }
  // Connectivity check
  if err := db.Ping(); err != nil {
    log.Fatalln("Error from database ping:", err)
  }
  // Create the store
  st := chapter1.New(db)
  st.CreateUsers(context.Background(),
  chapter1.CreateUsersParams{
    UserName:     "testuser",
    PassWordHash: "hash",
    Name:         "test",
  })
}

The app is doing the following:

  1. Initializing the URL and opening the database
  2. Pinging the database
  3. Creating a new user using the CreateUsers(..) function

Make sure you are in the chapter1 directory and build the application by running the following command:

go build -o chapter1

The compiler will generate a new executable called chapter1. Execute the file, and on a successful run, you will see the data inserted successfully into the users table:

2022/05/15 16:10:49 Done!
Name : test, ID : 1

We have completed setting up everything from the database and using sqlc to generate the relevant Go code. In the next section, we are going to put everything together for ease of development.

Building the makefile

A makefile is a file that is used by the make utility; it contains a set of tasks consisting of different combined shell scripts. Makefiles are most used to perform operations such as compiling source code, installing executables, performing checks, and many more. The make utility is available for both macOS and Linux, while in Windows, you need to use Cygwin (https://www.cygwin.com/) or NMake (https://docs.microsoft.com/en-us/cpp/build/reference/nmake-reference).

We will create the makefile to automate the steps that we have performed in this chapter. This will make it easy to do the process repetitively when required without typing it manually. We are going to create a makefile that will do tasks such as the following:

  • Bringing up/down Postgres
  • Generating code using sqlc

The makefile can be seen in the chapter1 directory; the following shows a snippet of the script:

..
.PHONY : postgresup postgresdown psql createdb teardown_recreate generate
postgresup:
    docker run --name test-postgres -v $(PWD):/usr/share/chapter1 -e POSTGRES_PASSWORD=$(DB_PWD) -p 5432:5432 -d $(DB_NAME)
...
# task to create database without typing it manually
createdb:
    docker exec -it test-postgres psql $(PSQLURL) -c "\i /usr/share/chapter1/db/schema.sql"
...

With the makefile, you can now bring up the database easily using this command:

make postgresup

The following is used to bring down the database:

make postgresdown

sqlc will need to be invoked to regenerate the auto-generated code whenever changes are made to the schema and SQL queries. You can use the following command to regenerate the files:

make generate 

Summary

In this chapter, we have covered the different stages that we need to go through to set up the database for our fitness application. We have also written a makefile to save us time by automating different database-related tasks that will be needed for the development process.

In the next chapter, we will look at logging for our sample application. Logging is a simple, yet crucial component. Applications use logging to provide visibility into the running state of an application.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn how to structure your Go projects, be smarter with SQLc, create middleware and secure your apps
  • Explore different frontend frameworks and dive into Vue and Tailwind CSS
  • Use Terraform and Docker and deploy in minutes

Description

Go is a modern programming language with capabilities to enable high-performance app development. With its growing web framework ecosystem, Go is a preferred choice for building complete web apps. This practical guide will enable you to take your Go skills to the next level building full stack apps. This book walks you through creating and developing a complete modern web service from auth, middleware, server-side rendering, databases, and modern frontend frameworks and Go-powered APIs. You’ll start by structuring the app and important aspects such as networking, before integrating all the different parts together to build a complete web product. Next, you’ll learn how to build and ship a complete product by starting with the fundamental building blocks of creating a Go backend. You’ll apply best practices for cookies, APIs, and security, and level up your skills with the fastest growing frontend framework, Vue. Once your full stack application is ready, you’ll understand how to push the app to production and be prepared to serve customers and share it with the world. By the end of this book, you’ll have learned how to build and ship secure, scalable, and complete products and how to combine Golang with existing products using best practices.

Who is this book for?

This book is for Go programmers who want to combine the power of the Go language with modern web development technologies to build complete web apps from frontend to backend. The book assumes beginner-level knowledge of HTML, CSS, and the web.

What you will learn

  • Discover how to quickly scaffold, structure, and build your Golang applications
  • Design and build databases using PostgreSQL and SQLc to generate type-safe SQL code
  • Monitor applications with centralized logging and metrics collection for high performance
  • Explore frontend frameworks and libraries such as Vuetify, Buefy, and Tailwind CSS to build a responsive frontend for your app
  • Communicate securely between the frontend and backend with cookies and session handling with middleware
  • Understand how to package applications using Docker and set up CI pipelines in GitHub
Estimated delivery fee Deliver to Czechia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 24, 2023
Length: 302 pages
Edition : 1st
Language : English
ISBN-13 : 9781803234199
Vendor :
Google
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Czechia

Premium delivery 7 - 10 business days

€25.95
(Includes tracking information)

Product Details

Publication date : Feb 24, 2023
Length: 302 pages
Edition : 1st
Language : English
ISBN-13 : 9781803234199
Vendor :
Google
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 89.97
Full-Stack Web Development with Go
€29.99
Test-Driven Development in Go
€29.99
Effective Concurrency in Go
€29.99
Total 89.97 Stars icon
Banner background image

Table of Contents

20 Chapters
Part 1: Building a Golang Backend Chevron down icon Chevron up icon
Chapter 1: Building the Database and Model Chevron down icon Chevron up icon
Chapter 2: Application Logging Chevron down icon Chevron up icon
Chapter 3: Application Metrics and Tracing Chevron down icon Chevron up icon
Part 2:Serving Web Content Chevron down icon Chevron up icon
Chapter 4: Serving and Embedding HTML Content Chevron down icon Chevron up icon
Chapter 5: Securing the Backend and Middleware Chevron down icon Chevron up icon
Chapter 6: Moving to API-First Chevron down icon Chevron up icon
Part 3:Single-Page Apps with Vue and Go Chevron down icon Chevron up icon
Chapter 7: Frontend Frameworks Chevron down icon Chevron up icon
Chapter 8: Frontend Libraries Chevron down icon Chevron up icon
Chapter 9: Tailwind, Middleware, and CORS Chevron down icon Chevron up icon
Chapter 10: Session Management Chevron down icon Chevron up icon
Part 4:Release and Deployment Chevron down icon Chevron up icon
Chapter 11: Feature Flags Chevron down icon Chevron up icon
Chapter 12: Building Continuous Integration Chevron down icon Chevron up icon
Chapter 13: Dockerizing an Application Chevron down icon Chevron up icon
Chapter 14: Cloud Deployment Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.6
(5 Ratings)
5 star 60%
4 star 0%
3 star 0%
2 star 20%
1 star 20%
Amazon Customer Apr 11, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As a VUE Front-End Developer, I was looking to expand my knowledge on the Backend and Full-Stack. Not really knowing what language to pick up or choose, I was always interested in trying out Go. I came across this E-Book and thought it was the perfect opportunity to read on my own pace. I was really impressed on how so much information was broken down and simplified. The best thing is that it covers other Front-Ends and frameworks, so this E-Book is a great choice for most developers. Can't recommend this enough. Go Go Golang!
Amazon Verified review Amazon
Oybek Apr 29, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I read this book and learn pretty many things about building a website from zero to hero using Golang and VueJS. If you are willing to learn how to build a website with Golang and VueJS, I kindly recommend this book to read as it has very efficient ways to build websites.
Amazon Verified review Amazon
- Jordan R May 03, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
'Full Stack Web Development with Go' provides a comprehensive guide to building web applications using the Go programming language. This book covers a wide range of topics. With clear explanations and practical examples, this book is a valuable resource for Beginners and Experts alike.-J
Amazon Verified review Amazon
Michael Apr 12, 2023
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
TLDR; I cannot recommend this book to anyone in it's current written form, and the two stars come from the fact that the authors cover topics pertaining to full-stack development and include some guidance for building out a Golang API server and connect it to a Vue.js browser app.As a primarily back-end Golang developer nowadays, I do have years of "full-stack" development experience. With that in mind, I was excited to have the opportunity to review a book attempting to join Golang with a front-end framework I have yet to actually use Vue.js. With the pleasantries aside, lets begin the actual reason this book was not for me.I initially took detailed notes on the information being presented within the book. I stopped taking notes around chapter 4 when I realized I wasn't actually getting anything out of the content I was reading. The initial trigger for me was the database diagram in chapter 1; I spent way too long pondering why someone would build out a database for the pretend app in such a way. Then as I continued reading, I realized that the first chapter's sole focus was on "building out a DB" with a Golang library / command line utility (cli), but gave zero focus on the actual design or even the queries required to build the DB using the cli. Maybe this will be addressed in chapter 2, 3... nope the author's decided that logging to a central server (the entire focus of chapter 2) and about metrics gathering (chapter 3) were more important topics to discuss.After chapter 3 was when I stopped focusing on the content and just started using the book as a pseudo reference guide to give me words to type into a search engine and begin my own journey of learning.Overall, the biggest issue I have with the book is it was published in 2023 and yet it feels like the content was written from information from a decade ago. Sure, I have not had to write a web app for a few years, but even I know that there is a huge push to move back to Server Side Rendering and this book barely gives it a paragraph blurb that it exists.If you have made it this far, and are still considering the purchase of this book, I would advise you to use this book as pseudo reference only and a spring board to give yourself the keywords required to search out better sources of the content.
Amazon Verified review Amazon
Dume Forwan May 01, 2023
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
The table of contents lead me to believe we'd be covering the full stack. Instead of rapid web dev using Golang, we get a ton of background that never quite gets around to delivering on the promise of the premise. Possibly the worst of approximately a hundred coding books I've bought over the last decade.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela