Hands-On Full Stack Development with Go

Book description

Create a real-world application in Go and explore various frameworks and methodologies for full-stack development

Key Features

  • Build a responsive front end by using the powerful React framework
  • Build web APIs and middleware in the Go language by making use of the popular Gin framework
  • Build an Isomorphic Go React application via GopherJS
  • Perform unit tests, and benchmarking on your web API

Book Description

The Go programming language has been rapidly adopted by developers for building web applications. With its impressive performance and ease of development, Go enjoys the support of a wide variety of open source frameworks, for building scalable and high-performant web services and apps. Hands-On Full Stack Development with Go is a comprehensive guide that covers all aspects of full stack development with Go.

This clearly written, example-rich book begins with a practical exposure to Go development and moves on to build a frontend with the popular React framework. From there, you will build RESTful web APIs utilizing the Gin framework. After that, we will dive deeper into important software backend concepts, such as connecting to the database via an ORM, designing routes for your services, securing your services, and even charging credit cards via the popular Stripe API. We will also cover how to test, and benchmark your applications efficiently in a production environment. In the concluding chapters, we will cover isomorphic developments in pure Go by learning about GopherJS. As you progress through the book, you'll gradually build a musical instrument online store application from scratch.

By the end of the book, you will be confident in taking on full stack web applications in Go.

What you will learn

  • Understand Go programming by building a real-world application
  • Learn the React framework to develop a frontend for your application
  • Understand isomorphic web development utilizing the GopherJS framework
  • Explore methods to write RESTful web APIs in Go using the Gin framework
  • Learn practical topics such as ORM layers, secure communications, and Stripe's API
  • Learn methods to benchmark and test web APIs in Go

Who this book is for

Hands-On Full Stack Development with Go will appeal to developers who are looking to start building amazing full stack web applications in Go. Basic knowhow of Go language and JavaScript is expected. The book targets web developers who are looking to move to the Go language.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Full Stack Development with Go
  3. Dedication
  4. About Packt
    1. Why subscribe?
    2. Packt.com
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Section 1: The Go Language
  8. Welcome to Full Stack Go
    1. What is full stack development?
    2. What will we build?
      1. The application architecture
    3. The outline of this book
  9. Building Blocks of the Go Language
    1. Technical requirements
      1. Go's playground
      2. Setting up Go's workspace
    2. Packages, variables, data types, and pointers
      1. Packages
      2. Variables and data types
      3. Pointers
    3. Functions and closures
      1. Functions – the basics
      2. Functions – accessing functions from other packages
      3. Closures
    4. Go data structures
      1. Arrays
      2. Slices
      3. Maps
      4. Struct
      5. Methods
        1. Type embedding
    5. Interfaces
    6. Conditional statements and loops
      1. The if statement
      2. The switch statement
      3. Loops
    7. Panics, recovers, and defers
    8. Summary
    9. Questions
    10. Further reading
  10. Go Concurrency
    1. What is concurrency?
    2. Goroutines
    3. Go channels
      1. Regular channels
      2. Buffered channels
    4. The select statement
    5. The sync package
      1. The simple mutex
      2. The read-write mutex
      3. Wait groups
    6. Summary
    7. Questions
    8. Further reading
  11. Section 2: The Frontend
  12. Frontend with React.js
    1. Prerequisites and technical requirements
    2. The GoMusic project
      1. Node.js and the npm
      2. HTML, CSS, and Bootstrap
      3. Project code
    3. The React framework
      1. How to construct React applications
      2. Setting up the project
        1. Installing React
        2. Preparing the new project
      3. JSX and React elements
      4. React components
        1. React application design
        2. Props
        3. State
          1. Initializing the state object
          2. Setting our state
      5. Developer tools
    4. Summary
    5. Questions
    6. Further reading
  13. Building a Frontend for GoMusic
    1. Prerequisites and technical requirements
    2. Building GoMusic
      1. Main pages
        1. The navigational menu
        2. The Products and Promotions pages
        3. The About page
      2. Modal dialog windows and handling credit cards
        1. The Buy Item modal window outline
        2. Credit card handling with React and Stripe
          1. Creating a child React component to host Stripe elements
          2. Making use of Stripe elements to handle credit card information
          3. Submitting a credit card token to the backend
          4. Creating a parent StripeProvider component
        3. The Sign in and Register modal windows
        4. Handling forms in the React framework
        5. The Sign in page
        6. The Registration form
      3. User pages
        1. The orders page
        2. The user page navigational menu
      4. Putting it all together – routes
    3. Summary
    4. Questions
    5. Further reading
  14. Section 3: Web APIs and Middleware in Go
  15. RESTful Web APIs in Go with the Gin Framework
    1. Technical requirements
    2. RESTful APIs
      1. Overview
        1. The client-server architecture
        2. URLs
        3. HTTP methods
    3. The Gin framework
      1. Models and the database layer
        1. Models
        2. The database layer interface
    4. Implementing RESTful APIs using the Gin framework
      1. Defining routes
      2. Creating handlers
        1. Getting a full list of available products
        2. Getting a list of promotions
        3. Sign in new users or add new users
        4. Sign out requests
        5. Getting orders for a specific user
        6. Charging a credit card
      3. Putting it all together
    5. Summary
    6. Questions
    7. Further reading
  16. Advanced Web Go Applications with Gin and React
    1. Technical requirements
    2. The database layer
      1. Relational databases
        1. Setting up
          1. The customer table
          2. The orders table
          3. The products table
      2. ORM
        1. GORM
        2. Implementing the database layer
    3. Middleware
      1. Custom middleware
    4. Security
      1. Certificates and private keys
        1. Establishing trust between the client and the server
        2. Agreeing on, and using an encryption key
      2. Supporting HTTPS in Gin
      3. Password hashing
        1. Implementing password hashing
        2. Comparing the password
    5. Credit card handling
      1. Credit card handling at the backend
    6. Revisiting the frontend code
      1. The app structure
      2. Interactions between the frontend and the backend
      3. Using cookies
      4. Deploying the frontend application
    7. Summary
    8. Questions
    9. Further reading
  17. Testing and Benchmarking Your Web API
    1. Testing in Go
      1. Mocking
        1. Creating a mock db type
      2. Unit testing in Go
        1. Table-driven development
    2. Benchmarking
    3. Summary
    4. Questions
    5. Further reading
  18. Introduction to Isomorphic Go with GopherJS
    1. Technical requirements
    2. GopherJS fundamentals
      1. GopherJS types
        1. Object types
      2. Calling JavaScript functions from your Go code
      3. GopherJS commands
      4. Go bindings
      5. Exporting code
        1. Go Methods
        2. Goroutines
    3. GopherJS with React
      1. The project
        1. The project application's architecture
      2. Building the React application in Go
        1. Building a custom component
    4. Summary
    5. Questions
    6. Further reading
  19. Where to Go from Here?
    1. Cloud-native applications
      1. Microservices
      2. Containers
      3. Serverless applications
      4. Continuous delivery
    2. React Native
      1. What is React Native?
      2. React.js versus React Native
        1. Similarities between React.js and React Native
        2. Differences between React.js and React Native
        3. Expo
    3. Summary
    4. Questions
  20. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Hands-On Full Stack Development with Go
  • Author(s): Mina Andrawos
  • Release date: March 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789130751