Название: Go Cookbook: Expert Solutions for Commonly Needed Go Tasks (6th Early Release) Автор: Sau Sheong Chang Издательство: O’Reilly Media, Inc. Год: 2023-04-07 Страниц: 224 Язык: английский Формат: pdf, epub, mobi Размер: 10.1 MB
Go is an increasingly popular language for programming everything from web applications to distributed network services. This practical guide provides recipes to help you unravel common problems and perform useful tasks when working with Go. Each recipe includes self-contained code solutions that you can freely use, along with a discussion of how and why they work. Programmers new to Go can quickly ramp up their knowledge while accomplishing useful tasks, and experienced Go developers can save time by cutting and pasting proven code directly into their applications.
As programmers we often treat error handling as tedious work and an after-thought. That’s generally an error by itself. In fact, just like how we should treat testing, error handling should be top of mind and recovering from the error should be part of good software design. In Go, error handling is treated pretty seriously, though a bit unconventionally. Go has the errors package in the standard library that provides many functions to manipulate errors but most of error handling in Go is built into the language or is part of the idiomatic way of programming in Go. In the Chapter 1 we’ll talk about some of the basic ideas in error handling in Go.
In many programming languages like Python and Java, error handling is done through exceptions. An exception is an object that represents an error and whenever something goes wrong, you can throw an exception. The calling function usually have a try and catch (or try and except in Python and so on) that handles anything that goes wrong. Go does this slightly differently (or completely differently, depending on how you look at it). Go doesn’t have exception handling. Instead of exceptions, it has errors. An error is a built-in type that represents an unexpected condition. Instead of throwing an exception you will create an error and returning it to the calling function.
Recipes include:
Creating a module Calling code from another module Returning and handling an error Converting strings to numbers (or converting numbers to strings) Modifying multiple characters in a string Creating substrings from a string Capturing string input And so much more
Скачать Go Cookbook: Expert Solutions for Commonly Needed Go Tasks (6th Early Release)
Внимание
Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться либо войти на сайт под своим именем.
Информация
Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.