Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Full-Stack Web Development with Go

You're reading from   Full-Stack Web Development with Go Build your web applications quickly using the Go programming language and Vue.js

Arrow left icon
Product type Paperback
Published in Feb 2023
Publisher Packt
ISBN-13 9781803234199
Length 302 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Nick Glynn Nick Glynn
Author Profile Icon Nick Glynn
Nick Glynn
Nanik Tolaram Nanik Tolaram
Author Profile Icon Nanik Tolaram
Nanik Tolaram
Arrow right icon
View More author details
Toc

Table of Contents (21) Chapters Close

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

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 
You have been reading a chapter from
Full-Stack Web Development with Go
Published in: Feb 2023
Publisher: Packt
ISBN-13: 9781803234199
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime