Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Go Design Patterns

You're reading from   Go Design Patterns Best practices in software development and CSP

Arrow left icon
Product type Paperback
Published in Feb 2017
Publisher Packt
ISBN-13 9781786466204
Length 402 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Mario Castro Contreras Mario Castro Contreras
Author Profile Icon Mario Castro Contreras
Mario Castro Contreras
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Ready... Steady... Go! FREE CHAPTER 2. Creational Patterns - Singleton, Builder, Factory, Prototype, and Abstract Factory Design Patterns 3. Structural Patterns - Composite, Adapter, and Bridge Design Patterns 4. Structural Patterns - Proxy, Facade, Decorator, and Flyweight Design Patterns 5. Behavioral Patterns - Strategy, Chain of Responsibility, and Command Design Patterns 6. Behavioral Patterns - Template, Memento, and Interpreter Design Patterns 7. Behavioral Patterns - Visitor, State, Mediator, and Observer Design Patterns 8. Introduction to Gos Concurrency 9. Concurrency Patterns - Barrier, Future, and Pipeline Design Patterns 10. Concurrency Patterns - Workers Pool and Publish/Subscriber Design Patterns

Starting with Hello World

This wouldn't be a good book without a Hello World example. Our Hello World example can't be simpler, open your favorite text editor and create a file called main.go within our $GOPATH/src/[your_name]/hello_world with the following content:

package main 
 
func main(){ 
println("Hello World!") 
} 

Save the file. To run our program, open the Terminal window of your operating system:

  • In Linux, go to programs and find a program called Terminal.
  • In Windows, hit Windows + R, type cmd without quotes on the new window and hit Enter.
  • In Mac OS X, hit Command + Space to open a spotlight search, type terminal without quotes. The terminal app must be highlighted so hit Enter.

Once we are in our terminal, navigate to the folder where we have created our main.go file. This should be under your $GOPATH/src/[your_name]/hello_world and execute it:

go run main.go
Hello World!

That's all. The go run [file] command will compile and execute our application but it won't generate an executable file. If you want just to build it and get an executable file, you must build the app using the following command:

go build -o hello_world

Nothing happens. But if you search in the current directory (ls command in Linux and Mac OS X; and dir in Windows), you'll find an executable file with the name hello_world. We have given this name to the executable file when we wrote -o hello_world command while building. You can now execute this file:

/hello_world
Hello World!

And our message appeared! In Windows, you just need to type the name of the .exe file to get the same result.

Tip

The go run [my_main_file.go] command will build and execute the app without intermediate files. The go build -o [filename] command will create an executable file that I can take anywhere and has no dependencies.

You have been reading a chapter from
Go Design Patterns
Published in: Feb 2017
Publisher: Packt
ISBN-13: 9781786466204
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image