- Go Programming Blueprints(Second Edition)
- Mat Ryer
- 395字
- 2021-07-08 10:40:01
Chapter 2. Adding User Accounts
The chat application we built in the previous chapter focused on high performance transmission of messages from the clients to the server and back again. However, the way things stand, our users have no way of knowing who they would be talking to. One solution to this problem is building some kind of sign-up and login functionality and letting our users create accounts and authenticate themselves before they can open the chat page.
Whenever we are about to build something from scratch, we must ask ourselves how others have solved this problem before (it is extremely rare to encounter genuinely original problems) and whether any open solutions or standards already exist that we can make use of. Authorization and authentication can hardly be considered new problems, especially in the world of the Web, with many different protocols out there to choose from. So how do we decide the best option to pursue? As always, we must look at this question from the point of view of the user.
A lot of websites these days allow you to sign in using your accounts that exist elsewhere on a variety of social media or community websites. This saves users the tedious job of entering all of their account information over and over again as they decide to try out different products and services. It also has a positive effect on the conversion rates for new sites.
In this chapter, we will enhance our chat codebase to add authorization, which will allow our users to sign in using Google, Facebook, or GitHub, and you'll see how easy it is to add other sign-in portals too. In order to join the chat, users must first sign in. Following this, we will use the authorized data to augment our user experience so everyone knows who is in the room and who said what.
In this chapter, you will learn to:
- Use the decorator pattern to wrap
http.Handler
types in order to add additional functionality to handlers - Serve HTTP endpoints with dynamic paths
- Use the
gomniauth
open source project to access authentication services - Get and set cookies using the
http
package - Encode objects as Base64 and back to normal again
- Send and receive JSON data over a web socket
- Give different types of data to templates
- Work with the channels of your own types
- 案例式C語(yǔ)言程序設(shè)計(jì)
- 自己動(dòng)手寫搜索引擎
- 微信公眾平臺(tái)與小程序開發(fā):從零搭建整套系統(tǒng)
- C++程序設(shè)計(jì)(第3版)
- Mastering SVG
- JavaScript+jQuery開發(fā)實(shí)戰(zhàn)
- HDInsight Essentials(Second Edition)
- Getting Started with LLVM Core Libraries
- 西門子S7-200 SMART PLC編程從入門到實(shí)踐
- C/C++程序員面試指南
- Qt5 C++ GUI Programming Cookbook
- Mastering Docker
- 零基礎(chǔ)學(xué)C語(yǔ)言(第4版)
- AI自動(dòng)化測(cè)試:技術(shù)原理、平臺(tái)搭建與工程實(shí)踐
- 軟件測(cè)試(慕課版)