Network Programming with Go Language: Essential Skills for Programming, Using and Securing Networks with Open Source Google Golang

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Dive into key topics in network architecture implemented with the Google-backed open source Go programming language. Networking topics such as data serialization, application level protocols, character sets and encodings are discussed and demonstrated in Go. This book has been updated to the Go version 1.18 which includes modules, generics, and fuzzing along with updated and additional examples.


Beyond the fundamentals,
Network Programming with Go, Second Edition covers key networking and security issues such as HTTP protocol changes, validation and templates, remote procedure call (RPC) and REST comparison, and more. Additionally, authors Ronald Petty and Jan Newmarch guide you in building and connecting to a complete web server based on Go. Along the way, use of a Go web toolkit (Gorilla) will be employed.


This book can serve as both an essential learning guide and reference on networking concepts and implementation in Go.  Free source code is available on Github for this book under Creative Commons open source license.


What You Will Learn

  • Perform network programming with Go (including JSON and RPC)
  • Understand Gorilla, the Golang web toolkit, and how to use it
  • Implement a microservice architecture with Go
  • Leverage Go features such as generics, fuzzing
  • Master syscalls and how to employ them with Go

Who This Book Is For
Anyone interested in learning networking concepts implemented in modern Go. Basic knowledge in Go is assumed, however, the content and examples in this book are approachable with modest development experience in other languages.

Author(s): Jan Newmarch, Ronald Petty
Edition: 2
Publisher: Apress
Year: 2022

Language: English
Pages: 402

Table of Contents
About the Authors
About the Technical Reviewer
Acknowledgments
Preface to the Second Edition
Preface to the First Edition
Chapter 1: Architectural Layers
Protocol Layers
ISO OSI Protocol
OSI Layers
TCP/IP Protocol
Some Alternative Protocols
Networking
Gateways
Host-Level Networking
Packet Encapsulation
Connection Models
Connection Oriented
Connectionless
Communications Models
Message Passing
Remote Procedure Call
Distributed Computing Models
Client-Server System
Client-Server Application
Server Distribution
Communication Flows
Synchronous Communication
Asynchronous Communication
Streaming Communication
Publish/Subscribe
Component Distribution
Gartner Classification
Example: Distributed Database
Example: Network File Service
Example: Web
Example: Terminal Emulation
Example: Secure Shell
Three-Tier Models
Fat vs. Thin
Middleware Model
Middleware Examples
Middleware Functions
Continuum of Processing
Points of Failure
Acceptance Factors
Thoughts on Distributed Computing
Transparency
Access Transparency
Location Transparency
Migration Transparency
Replication Transparency
Concurrency Transparency
Scalability Transparency
Performance Transparency
Failure Transparency
Eight Fallacies of Distributed Computing
Fallacy: The Network Is Reliable
Fallacy: Latency Is Zero
Fallacy: Bandwidth Is Infinite
Fallacy: The Network Is Secure
Fallacy: Topology Doesn’t Change
Fallacy: There Is One Administrator
Fallacy: Transport Cost Is Zero
Fallacy: The Network Is Homogeneous
Conclusion
Chapter 2: Overview of the Go Language
Types
Slices and Arrays
Maps
Pointers
Functions
Structures
Methods
Multithreading
Packages
Modules
Type Conversion
Statements
GOPATH
Running Go Programs
Standard Libraries
Error Values
Conclusion
Chapter 3: Socket-Level Programming
The TCP/IP Stack
IP Datagrams
UDP
TCP
Internet Addresses
IPv4 Addresses
IPv6 Addresses
IP Address Type
Using Available Documentation and Examples
The IPMask Type
Basic Routing
The IPAddr Type
Host Canonical Name and Addresses Lookup
Services
Ports
The TCPAddr Type
TCP Sockets
TCP Client
A Daytime Server
Multithreaded Server
Controlling TCP Connections
Timeout
Staying Alive
UDP Datagrams
Server Listening on Multiple Sockets
The Conn, PacketConn, and Listener Types
Raw Sockets and the IPConn Type
Conclusion
Chapter 4: Data Serialization
Structured Data
Mutual Agreement
Self-Describing Data
Encoding Packages
ASN.1
ASN.1 Daytime Client and Server
JSON
A Client and A Server
The Gob Package
A Client and A Server
Encoding Binary Data As Strings
Protocol Buffers
Installing and Compiling Protocol Buffers
The Generated personv3.pb.go File
Using the Generated Code
Conclusion
Chapter 5: Application-Level Protocols
Protocol Design
Why Should You Worry?
Version Control
The Web
Message Format
Data Format
Byte Format
Character Format
A Simple Example
A Stand-Alone Application
The Client-Server Application
The Client Side
Alternative Presentation Aspects
The Server Side
Protocol: Informal
Text Protocol
Server Code
Client Code
Textproto Package
State Information
Application State Transition Diagram
Client-State Transition Diagrams
Server-State Transition Diagrams
Server Pseudocode
Conclusion
Chapter 6: Managing Character Sets and Encodings
Definitions
Character
Character Repertoire/Character Set
Character Code
Character Encoding
Transport Encoding
ASCII
ISO 8859
Unicode
UTF-8, Go, and Runes
UTF-8 Client and Server
ASCII Client and Server
UTF-16 and Go
Little-Endian and Big-Endian
UTF-16 Client and Server
Unicode Gotchas
ISO 8859 and Go
Other Character Sets and Go
Conclusion
Chapter 7: Security
ISO Security Architecture
Functions and Levels
Mechanisms
Data Integrity
Symmetric Key Encryption
Public Key Encryption
X.509 Certificates
TLS
A Basic Client
Server Using a Self-Signed Certificate
Conclusion
Chapter 8: HTTP
URLs and Resources
i18n
HTTP Characteristics
Versions
HTTP/0.9
Response Format
HTTP/1.0
Request Format
Response Format
HTTP 1.1
HTTP Major Upgrades
HTTP/2
HTTP/3
Simple User Agents
The Response Type
The HEAD Method
The GET Method
Configuring HTTP Requests
The Client Object
Proxy Handling
Simple Proxy
Authenticating Proxy
HTTPS Connections by Clients
Servers
File Server
Handler Functions
Bypassing the Default Multiplexer
HTTPS
Conclusion
Chapter 9: Templates
Inserting Object Values
Using Templates
Pipelines
Defining Functions
Variables
Conditional Statements
The html/template Package
Conclusion
Chapter 10: A Complete Web Server
Browser Site Diagram
Browser Files
Basic Server
The listFlashCards Function
The manageFlashCards Function
The Chinese Dictionary
The Dictionary Type
Flashcard Sets
Fixing Accents
The ListWords Function
The showFlashCards Function
Presentation on the Browser
Running the Server
Conclusion
Chapter 11: HTML
The html/template Package
Tokenizing HTML
XHTML/HTML
JSON
Conclusion
Chapter 12: XML
Unmarshalling XML
Marshalling XML
Parsing XML
The StartElement Type
The EndElement Type
The CharData Type
The Comment Type
The ProcInst Type
The Directive Type
XHTML
HTML
Conclusion
Chapter 13: Remote Procedure Call
Go’s RPC
HTTP RPC Server
HTTP RPC Client
TCP RPC Server
TCP RPC Client
Matching Values
JSON
JSON RPC Server
JSON RPC Client
Conclusion
Chapter 14: REST
URIs and Resources
Representations
REST Verbs
The GET Verb
The PUT Verb
The DELETE Verb
The POST Verb
No Maintained State (That Is, Stateless)
HATEOAS
Representing Links
Transactions with REST
The Richardson Maturity Model
Flashcards Revisited
URLs
ServeMux (The Demultiplexer)
Content Negotiation
GET /
POST /
Handling Other URLs
The Complete Server
Client
Using REST or RPC
Conclusion
Chapter 15: WebSockets
WebSockets Server
The golang.org/x/net/websocket Package
The Message Object
The JSON Object
The Codec Type
WebSockets over TLS
WebSockets in an HTML Page
The github.com/gorilla/websocket Package
Echo Server
Echo Client
Conclusion
Chapter 16: Gorilla
Middleware Pattern
Standard Library ServeMux Examples
Customizing Muxes
gorilla/mux
Why Should We Care
Gorilla Handlers
Additional Gorilla Examples
gorilla/rpc
gorilla/schema
gorilla/securecookie
Conclusion
Chapter 17: Testing
Simple and Broken
httptest Package
Below HTTP
Leveraging the Standard Library
Conclusion
Appendix A: Fuzzing
Fuzzing in Go
Fuzzing Failures
Fuzzing Network-Related Artifacts
Conclusion
Appendix B: Generics
A Filtering Function Without Generics
Refactor Using Generics
Custom Constraints
Using Generics on Collections
How Not to Use Generics?
Conclusion
Index