• Complain

Agus Kurniawan - Go Programming by Example

Here you can read online Agus Kurniawan - Go Programming by Example full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2015, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Agus Kurniawan Go Programming by Example
  • Book:
    Go Programming by Example
  • Author:
  • Genre:
  • Year:
    2015
  • Rating:
    5 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 100
    • 1
    • 2
    • 3
    • 4
    • 5

Go Programming by Example: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Go Programming by Example" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Go Programming by Example — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Go Programming by Example" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Copyright

Go Programming by Example

Agus Kurniawan

1st Edition, 2015

Copyright 2015 Agus Kurniawan

* Cover photo is credit to Fajar Ramadhany, Bataviasoft, http://bataviasoft.com/.

** Go logo is taken from https://blog.golang.org/gopher .

Preface
Go was created by Robert Griesemer, Rob Pike, and Ken Thompson at Google in 2007. This book is a reference to the Go programming language. It describes all the elements of the language and illustrates their use with code examples.
Agus Kurniawan
Berlin & Depok, February 2015
1. Development Environment

This chapter explains introduction of Go. The official web of Go could be found on https://golang.org/. What is Go? Based on information from website, we could know what it is. Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.

1.1 Installation

Installation of Go application is easy. For Windows and Mac Platform, you download setup file from Go website, http://golang.org/doc/install. Run it and follow installation commands.

The next step is to configure GOROOT path For Windows platform you can add - photo 1

The next step is to configure GOROOT path. For Windows platform, you can add GOROOT variable on Environment Variables. For Mac/Linux, you can it on your bash profile.

For Windows platform you can add GO installation path for instance my Go - photo 2

For Windows platform, you can add GO installation path, for instance my Go installation path is c:/go/bin, into PATH variable on Environment Variables.

After configured you can verify Go version by typing this command on your - photo 3

After configured, you can verify Go version by typing this command on your Terminal or CMD for Windows.

$ go version

A sample output can be seen in Figure below, Mac platform.

The output of program on Windows platform 12 Development Tools - photo 4

The output of program on Windows platform.

12 Development Tools Basically you can use any text editor to write Go code - photo 5

1.2 Development Tools

Basically, you can use any text editor to write Go code. The following is a list of text editor:

  • vim
  • nano
  • Intellij IDEA, https://www.jetbrains.com/idea/
  • Sublime text, http://www.sublimetext.com/

A sample screenshot for Intellij IDEA is shown in Figure below.

13 Hello World How to get started with Go well it is easy Firstly create a - photo 6

1.3 Hello World

How to get started with Go? well, it is easy. Firstly, create a folder, called hello.

$ mkdir hello $ cd hello

Then, create a file, called main.go, on the hello folder. Write this code for main.go file.

package main import "fmt" func main() { fmt.Println( "Hello, go!" )}

Save this file. Then, back to your Terminal. You can build and run it.

$ go build $ go run main.go

In this case, it will generate an executable file based on your platform.

A sample program output can be seen in Figure below.

14 Go Packages There are a lot of Go packages that you can use The list of Go - photo 7

1.4 Go Packages

There are a lot of Go packages that you can use. The list of Go packages can seen on this link https://golang.org/pkg/. In this book, we will explore some Go standard packages. We also try to build own Go package.

2. Go Programming Language

This chapter explains the basic of Go programming language.

2.1 Common Rule

Go language uses "C family" as primary language but we don't write ";" at the end of syntax. Here is the syntax rule:

syntax_code1syntax_code2syntax_code3
2.2 Variables

In this section, we explore how to define a variable and assign its value.

2.2.1 Declaring Variable

To declare a variable called myvar and data type is data_type1, you can write the following script:

var myvar data_type1

The following is a sample script to declare some variables.

var str string var n, m int var mn float32

We also can define multiple variables as follows.

var ( name string email string age int )

Once declared, these variables can be used to store any type data.

2.2.2 Assigning Variables

Variable that you already declare can be assigned by a value. It can done using the equals sign (=). For example, variable str will assign a string value "Hello World", you would write this:

str = "Hello World" n = m = mn = 2.45

We also can declare a variable and assign its value.

var city string = "London" var x int =

Another option, we can declare a variable with defining data type using := syntax. Assign it with a value.

country := "DE" val :=
2.2.3 Demo

For illustration for declaring variables using Go, create a folder, called vardemo. Then, create a file, called main.go.

Write the following script for main.go.

package main import "fmt" func main() { // declare variables var str string var n, m int var mn float32 // assign values str = "Hello World" n = m = mn = 2.45 fmt.Println( "value of str= " ,str) fmt.Println( "value of n= " ,n) fmt.Println( "value of m= " ,m) fmt.Println( "value of mn= " ,mn) // declare and assign values to variables var city string = "London" var x int = fmt.Println( "value of city= " ,city) fmt.Println( "value of x= " ,x) // declare variable with defining its type country := "DE" val := fmt.Println( "value of country= " ,country) fmt.Println( "value of val= " ,val) // define multiple variables var ( name string email string age int ) name = "john" email = "john@email.com" age = fmt.Println(name) fmt.Println(email) fmt.Println(age)}

Save this file.

Then, try to build and run it.

$ cd vardemo $ go build $ go run main.go

A sample output can be seen in Figure below.

23 Comment You may explain how to work on your code with writing comments To - photo 8

2.3 Comment

You may explain how to work on your code with writing comments. To do it, you can use // and /* */ syntax. Here is sample code:

// declare variables var str string var n, m int var mn float32 // assign values str = "Hello World" n = m = mn = 2.45 /* print the result */ fmt.Println( "value of str= " ,str)
2.4 Arithmetic Operations

Go supports the same four basic arithmetic operations such as addition, subtraction, multiplication, and division. For testing, create a folder arithdemo. Then, create a file, called main.go.

The following is the code illustration for basic arithmetic in main.go:

package main import "fmt" func main() { // declare variables var a, b int // assign values a = b = // arithmetic operation // addition c := a + b fmt.Printf( "%d + %d = %d \n" ,a,b,c) // subtraction d := a - b fmt.Printf( "%d - %d = %d \n" ,a,b,d) // division e := float32 (a) / float32 (b) fmt.Printf( "%d / %d = %.2f \n" ,a,b,e) // multiplication f := a * b fmt.Printf( "%d * %d = %d \n" ,a,b,f)}
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Go Programming by Example»

Look at similar books to Go Programming by Example. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Go Programming by Example»

Discussion, reviews of the book Go Programming by Example and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.