gobook.3186517259

Telechargé par OMAR TRIGUI
An Introduction to Programming in Go
Copyright © 2012 by Caleb Doxsey
All rights reserved. No part of this book may be
reproduced or transmitted in any form or by any
means, electronic or mechanical, including
photocopying, recording, or by any information storage
and retrieval system without the written permission of
the author, except where permitted by law.
ISBN: 978-1478355823
Cover art by Abigail Doxsey Anderson.
Portions of this text are reproduced from work created
and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution
License.
Contents
1 Getting Started 1
1.1 Files and Folders 2
1.2 The Terminal 5
1.3 Text Editors 9
1.4 Go Tools 13
2 Your First Program 15
2.1 How to Read a Go Program 17
3 Types 23
3.1 Numbers 24
3.2 Strings 29
3.3 Booleans 31
4 Variables 35
4.1 How to Name a Variable 39
4.2 Scope 40
4.3 Constants 43
4.4 Defining Multiple Variables 44
4.5 An Example Program 45
5 Control Structures 47
5.1 For 48
5.2 If 51
5.3 Switch 55
6 Arrays, Slices and Maps 58
6.1 Arrays 58
6.2 Slices 64
6.3 Maps 67
7 Functions 76
7.1 Your Second Function 77
7.2 Returning Multiple Values 82
7.3 Variadic Functions 82
7.4 Closure 84
7.5 Recursion 86
7.6 Defer, Panic & Recover 88
8 Pointers 92
8.1 The * and & operators 93
8.2 new 94
9 Structs and Interfaces 97
9.1 Structs 98
9.2 Methods 101
9.3 Interfaces 104
10 Concurrency 108
10.1 Goroutines 108
10.2 Channels 111
11 Packages 120
11.1 Creating Packages 121
11.2 Documentation 124
12 Testing 127
13 The Core Packages 132
13.1 Strings 132
13.2 Input / Output 134
13.3 Files & Folders 135
13.4 Errors 140
13.5 Containers & Sort 141
13.6 Hashes & Cryptography 144
13.7 Servers 147
13.8 Parsing Command Line Arguments 155
13.9 Synchronization Primitives 156
14 Next Steps 159
14.1 Study the Masters 159
14.2 Make Something 160
14.3 Team Up 161
1 Getting Started
Computer programming is the art, craft and science of
writing programs which define how computers operate.
This book will teach you how to write computer pro-
grams using a programming language designed by
Google named Go.
Go is a general purpose programming language with
advanced features and a clean syntax. Because of its
wide availability on a variety of platforms, its robust
well-documented common library, and its focus on good
software engineering principles, Go is an ideal lan-
guage to learn as your first programming language.
The process we use to write software using Go (and
most programming languages) is fairly straightfor-
ward:
1. Gather requirements
2. Find a solution
3. Write source code to implement the solution
1
1 / 165 100%

gobook.3186517259

Telechargé par OMAR TRIGUI
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !