The Go Programming Language - beyondkmp

[Pages:400] The Go Programming Language

This page intentionally left blank

The Go Programming Language

Alan A. A. Donovan

Google Inc.

Brian W. Kernighan

Princeton University

New York ? Boston ? Indianapolis ? San Francisco Toronto ? Montreal ? London ? Munich ? Paris ? Madrid Capetown ? Sydney ? Tokyo ? Singapore ? Mexico City

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at corpsales@ or (800) 382-3419. For government sales inquiries, please contact governmentsales@. For questions about sales outside the United States, please contact international@. Visit us on the Web: aw Library of Congress Control Number: 2015950709 Copyright ? 2016 Alan A. A. Donovan & Brian W. Kernighan All rights reserved. Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, 200 Old Tappan Road, Old Tappan, New Jersey 07675, or you may fax your request to (201) 236-3290. Front cover: Millau Viaduct, Tarn valley, southern France. A paragon of simplicity in modern engineering design, the viaduct replaced a convoluted path from capital to coast with a direct route over the clouds. ? Jean-Pierre Lescourret/Corbis. Back cover: the original Go gopher. ? 2009 Ren?e French. Used under Creative Commons Attributions 3.0 license. Typeset by the authors in Minion Pro, Lato, and Consolas, using Go, groff, ghostscript, and a host of other open-source Unix tools. Figures were created in Google Drawings. ISBN-13: 978-0-13-419044-0 ISBN-10: 0-13-419044-0 Text printed in the United States on recycled paper at RR Donnelley in Crawfordsville, Indiana. First printing, October 2015

For Leila and Meg

This page intentionally left blank

Preface The Origins of Go The Go Project Organization of the Book Where to Find More Information Acknowledgments

1. Tutorial 1.1. Hello, World 1.2. Command-Line Arguments 1.3. Finding Duplicate Lines 1.4. Animated GIFs 1.5. Fetching a URL 1.6. Fetching URLs Concurrently 1.7. A Web Server 1.8. Loose Ends

2. Program Structure 2.1. Names 2.2. Declarations 2.3. Variables 2.4. Assignments 2.5. Type Declarations 2.6. Packages and Files 2.7. Scope

vii

Contents

xi xii xiii xv xvi xvii

1 1 4 8 13 15 17 19 23

27 27 28 30 36 39 41 45

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download