Introducing Go: Build Reliable, Scalable Programs

Preparing link to download Please wait... Download

E-Book Overview

Perfect for beginners familiar with programming basics, this hands-on guide provides an easy introduction to Go, the general-purpose programming language from Google. Author Caleb Doxsey covers the language’s core features with step-by-step instructions and exercises in each chapter to help you practice what you learn.Go is a general-purpose programming language with a clean syntax and advanced features, including concurrency. This book provides the one-on-one support you need to get started with the language, with short, easily digestible chapters that build on one another. By the time you finish this book, not only will you be able to write real Go programs, youll be ready to tackle advanced techniques.

E-Book Content

Introducing Go BUILD RELIABLE, SCALABLE PROGRAMS Caleb Doxsey Introducing Go Build Reliable, Scalable Programs Caleb Doxsey Boston Introducing Go by Caleb Doxsey Copyright © 2016 Caleb Doxsey. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://safaribooksonline.com). For more information, contact our corporate/ institutional sales department: 800-998-9938 or [email protected] Editors: Brian MacDonald and Meghan Blanchette Production Editor: Shiny Kalapurakkel Copyeditor: Jasmine Kwityn Proofreader: James Fraleigh Indexer: WordCo Indexing Services, Inc. Interior Designer: David Futato Cover Designer: Karen Montgomery Illustrator: Rebecca Demarest First Edition January 2016: Revision History for the First Edition 2016-01-06: First Release See http://oreilly.com/catalog/errata.csp?isbn=9781491941959 for release details. While the publisher and the author have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the author disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights. 978-1-491-94195-9 [LSI] Table of Contents Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii 1. Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Machine Setup Text Editors The Terminal Environment Go Your First Program How to Read a Go Program Exercises 1 1 2 2 2 3 4 5 8 2. Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Numbers 10 Integers 10 Floating-Point Numbers 10 Example 11 Strings 12 Booleans 13 Exercises 16 3. Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . How to Name a Variable Scope Constants Defining Multiple Variables An Example Program Exercises 17 20 20 21 22 22 23 iii 4. Control Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .