Book description
Implement solutions by leveraging the power of the GO standard library and reducing dependency on external crates
About This Book
- Develop high quality, fast and portable applications by leveraging the power of Go Standard Library.
- Practical recipes that will help you work with the standard library algorithms to boost your productivity as a Go developer.
- Compose your own algorithms without forfeiting the simplicity and elegance of the Standard Library.
Who This Book Is For
This book is for Go developers who would like to explore the power of Golang and learn how to use the Go standard library for various functionalities. The book assumes basic Go programming knowledge.
What You Will Learn
- Access environmental variables
- Execute and work with child processes
- Manipulate strings by performing operations such as search, concatenate, and so on
- Parse and format the output of date/time information
- Operate on complex numbers and effective conversions between different number formats and bases
- Work with standard input and output
- Handle filesystem operations and file permissions
- Create TCP and HTTP servers, and access those servers with a client
- Utilize synchronization primitives
- Test your code
In Detail
Google's Golang will be the next talk of the town, with amazing features and a powerful library. This book will gear you up for using golang by taking you through recipes that will teach you how to leverage the standard library to implement a particular solution. This will enable Go developers to take advantage of using a rock-solid standard library instead of third-party frameworks.
The book begins by exploring the functionalities available for interaction between the environment and the operating system. We will explore common string operations, date/time manipulations, and numerical problems.
We'll then move on to working with the database, accessing the filesystem, and performing I/O operations. From a networking perspective, we will touch on client and server-side solutions. The basics of concurrency are also covered, before we wrap up with a few tips and tricks.
By the end of the book, you will have a good overview of the features of the Golang standard library and what you can achieve with them. Ultimately, you will be proficient in implementing solutions with powerful standard libraries.
Style and approach
Solution based approach showcasing the power of Go standard library for easy practical implementations.
Table of contents
- Title Page
- Copyright and Credits
- Packt Upsell
- Contributors
- Preface
-
Interacting with the Environment
- Introduction
- Retrieving the Golang version
- Accessing program arguments
- Creating a program interface with the flag package
- Getting and setting environment variables with default values
- Retrieving the current working directory
- Getting the current process PID
- Handling operating system signals
- Calling an external process
- Retrieving child process information
- Reading/writing from the child process
- Shutting down the application gracefully
- File configuration with functional options
-
Strings and Things
- Introduction
- Finding the substring in a string
- Breaking the string into words
- Joining the string slice with a separator
- Concatenating a string with writer
- Aligning text with tabwriter
- Replacing part of the string
- Finding the substring in text by the regex pattern
- Decoding a string from the non-Unicode charset
- Controlling case
- Parsing comma-separated data
- Managing whitespace in a string
- Indenting a text document
-
Dealing with Numbers
- Introduction
- Converting strings to numbers
- Comparing floating-point numbers
- Rounding floating-point numbers
- Floating-point arithmetics
- Formatting numbers
- Converting between binary, octal, decimal, and hexadecimal
- Formatting with the correct plurals
- Generating random numbers
- Operating complex numbers
- Converting between degrees and radians
- Taking logarithms
- Generating checksums
-
Once Upon a Time
- Introduction
- Finding today's date
- Formatting date to string
- Parsing the string into date
- Converting dates to epoch and vice versa
- Retrieving time units from the date
- Date arithmetics
- Finding the difference between two dates
- Converting between time zones
- Running the code block periodically
- Waiting a certain amount of time
- Timeout long-running operations
- Serializing the time and date
-
In and Out
- Introduction
- Reading standard input
- Writing standard output and error
- Opening a file by name
- Reading the file into a string
- Reading/writing a different charset
- Seeking a position within a file
- Reading and writing binary data
- Writing to multiple writers at once
- Piping between writer and reader
- Serializing objects to binary format
- Reading and writing ZIP files
- Parsing a large XML file effectively
- Extracting data from an incomplete JSON array
- Discovering the Filesystem
-
Connecting the Network
- Introduction
- Resolving local IP addresses
- Connecting to the remote server
- Resolving the domain by IP address and vice versa
- Connecting to the HTTP server
- Parsing and building a URL
- Creating an HTTP request
- Reading and writing HTTP headers
- Handling HTTP redirects
- Consuming the RESTful API
- Sending a simple email
- Calling the JSON-RPC service
-
Working with Databases
- Introduction
- Connecting the database
- Validating the connection
- Executing statements
- Operations with prepared statements
- Canceling the pending query
- Reading query result metadata
- Retrieving data from a query result
- Parsing the query result into a map
- Handling transactions
- Executing stored procedures and functions
-
Come to the Server Side
- Introduction
- Creating the TCP server
- Creating the UDP server
- Handling multiple clients
- Creating the HTTP Server
- Handling HTTP requests
- Creating HTTP middleware layer
- Serving static files
- Serving content generated with templates
- Handling redirects
- Handling cookies
- Gracefully shutdown the HTTP server
- Serving secured HTTP content
- Resolving form variables
- Fun with Concurrency
- Tips and Tricks
- Other Books You May Enjoy
Product information
- Title: Go Standard Library Cookbook
- Author(s):
- Release date: February 2018
- Publisher(s): Packt Publishing
- ISBN: 9781788475273
You might also like
book
Go Recipes: A Problem-Solution Approach
Solve your Go problems using a problem-solution approach. Each recipe is a self-contained answer to a …
book
Go Programming Cookbook - Second Edition
Tackle the trickiest of problems in Go programming with this practical guide Key Features Develop applications …
book
Go: Building Web Applications
Build real-world, production-ready solutions by harnessing the powerful features of Go About This Book An easy-to-follow …
video
Create a Web Application Scaffold Generator in Go
Step into the role of a platform engineer and build a command-line application for generating a …