Full-Stack Web Development with Go

Book description

A Go programmer's hands-on guide to go from building basic server-side templates to full single page apps using Tailwind CSS, Vue.js, and more

Key Features

  • 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

Book 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.

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

Who this book is 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.

Table of contents

  1. Full-Stack Web Development with Go
  2. Contributors
  3. About the authors
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Part 1: Building a Golang Backend
  7. Chapter 1: Building the Database and Model
    1. Technical requirements
    2. Installing Docker
    3. Setting up Postgres
    4. Designing the database
    5. Installing sqlc
    6. Using sqlc
    7. Setting up the database
    8. Generating CRUD with sqlc
    9. Building the makefile
    10. Summary
  8. Chapter 2: Application Logging
    1. Technical requirements
    2. Exploring Go standard logging
    3. Using golog
    4. Local logging
    5. Writing log messages to the logging server
    6. Configuring multiple outputs
    7. Summary
  9. Chapter 3: Application Metrics and Tracing
    1. Technical requirements
    2. Understanding OpenTelemetry
      1. The OpenTelemetry APIs and SDK
    3. Tracing applications
      1. Installing Jaeger
    4. Integrating the Jaeger SDK
      1. Integration with Jaeger
    5. Adding metrics using Prometheus
      1. Adding metrics using Prometheus
    6. Running docker-compose
    7. Summary
  10. Part 2:Serving Web Content
  11. Chapter 4: Serving and Embedding HTML Content
    1. Technical requirements
    2. Handling HTTP functions and Gorilla Mux
      1. Hello, World with defaults
      2. Building on the basics with Gorilla Mux
    3. Rendering static content
    4. Rendering dynamic content
    5. Using Go embed to bundle your content
    6. Summary
  12. Chapter 5: Securing the Backend and Middleware
    1. Technical requirements
    2. Adding authentication
      1. Creating our dummy user
      2. Authenticating a user
    3. Adding middleware
      1. Basic middleware
    4. Adding cookies and sessions
      1. Cookies and session handling
      2. Storing session information
      3. Using Redis for a session
    5. Summary
  13. Chapter 6: Moving to API-First
    1. Technical requirements
    2. Structuring an application
      1. Defining packages
    3. Exposing our REST API
      1. Cross-Origin Resource Sharing (CORS)
      2. JSON middleware
      3. Session middleware
    4. Converting to and from JSON
      1. Defining request model
      2. Defining a response model
    5. Reporting errors with JSON
      1. Using JSONError
      2. Using JSONMessage
    6. Summary
  14. Part 3:Single-Page Apps with Vue and Go
  15. Chapter 7: Frontend Frameworks
    1. Technical requirements
    2. Server-side rendering versus single-page apps
    3. Introducing React, Vue, and more
      1. React
      2. Svelte
      3. Vue
    4. Creating a Vue app
    5. Application and components
      1. Login page using Vue
      2. Using Vite
    6. Using Vue Router to move around
      1. Routing the login page
    7. Summary
  16. Chapter 8: Frontend Libraries
    1. Technical requirements
    2. Understanding Vuetify
    3. Setting up Vuetify
    4. Using UI components
    5. Understanding Buefy
    6. Bulma sample
    7. Setting up Buefy
    8. UI components
    9. Validating data entry with Vuelidate
    10. Better input handling with Cleave.JS
    11. Summary
  17. Chapter 9: Tailwind, Middleware, and CORS
    1. Technical requirements
    2. Introducing Tailwind
      1. Creating a new Tailwind and Vite project
    3. Consuming your Golang APIs
    4. CORS for secure applications
    5. Creating Vue middleware
    6. Summary
  18. Chapter 10: Session Management
    1. Technical requirements
    2. Session management and JWTs
      1. What’s a JWT?
    3. (Re)introducing Vue Router
    4. Navigation guards
    5. Defaults and error pages
    6. Summary
  19. Part 4:Release and Deployment
  20. Chapter 11: Feature Flags
    1. Technical requirements
    2. An introduction to feature flags
    3. Feature flag configuration
    4. Use cases for using feature flags
      1. Installing the feature flag server
    5. The high-level architecture of feature flags
    6. Integration of the feature flag
      1. Web application
      2. Microservice integration
    7. Summary
  21. Chapter 12: Building Continuous Integration
    1. Technical requirements
    2. Importance of CI
      1. Setting up GitHub
    3. GitHub Actions
    4. Publishing Docker images
      1. Dockerfile
    5. GitHub Packages
      1. Publishing to GitHub Packages
      2. Pulling from GitHub Packages
    6. Summary
  22. Chapter 13: Dockerizing an Application
    1. Technical requirements
    2. Installing Docker
    3. Using Docker
    4. Docker images
    5. Running images as containers
    6. Building and packaging images
    7. Docker Compose
    8. Summary
  23. Chapter 14: Cloud Deployment
    1. Technical requirements
    2. AWS refresher
      1. Amazon Elastic Compute Cloud
      2. Virtual Private Cloud
      3. Database storage
      4. Elastic Container Service
      5. AWS tools
    3. Understanding and using Terraform
      1. What is Terraform?
      2. Installing Terraform
    4. Terraform basic commands
      1. The init command
      2. The plan command
      3. The destroy command
    5. Coding in Terraform
      1. Providers
    6. Terraform examples
      1. Pulling from GitHub Packages
      2. AWS EC2 setup
      3. Deploying to ECS with a load balancer
    7. Summary
  24. Index
    1. Why subscribe?
  25. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Download a free PDF copy of this book

Product information

  • Title: Full-Stack Web Development with Go
  • Author(s): Nanik Tolaram, Nick Glynn
  • Release date: February 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781803234199