Go programming language: The Ultimate Beginner's Guide to Learn Go Programming Step by Step by lnc mEm & Bach John
Author:lnc, mEm & Bach, John [lnc, mEm]
Language: eng
Format: epub
Published: 2021-01-04T16:00:00+00:00
The main topics covered in this chapter are as follows:
- Write comments.
- Libraries and import.
- Functions.
- Data types.
- Named return values.
- Variables and memory.
- Control sentences.
- Generate functions.
- Deferred implementation.
- Interfaces.
- Multiple inputs.
- Error handling.
- Simultaneous implementation.
- Web
Write comments:
To write a one-line comment
// single line comment
Type a comment with more than one line
/ * Multi-
line comment * /
Libraries and import
Each source file starts with the keyword packag. The main keyword is used to identify the file as an operational file, not a library.
package main
To import an office package into the file, we use the Import instruction in the following way:
import (
"fmt" // package in the standard language library
"io / ioutil" // I / O functions are applied
m "math" // We use the letter m to shorten the name of the mathematical functions library
"net / http" // web server
"os" // functions at the operating system level such as handling file s
"strconv" // Text conversions
)
Functions
Functions are defined by the word func followed by the function name.
The main function is private, and is the entrance to the program's executable file (the Go language uses ornate braces {} to define parts / blocks).
func main () {
// To output text on the main output unit (stdout), we use the Println function in the fmt library
fmt.Println ("Hello world!")
// Call a function from the same current package
beyondHello ()
}
Functions need parentheses that receive Parameters, and even in the absence of parameters, parentheses are required.
func beyondHello () {
// Variable declaration (variable must be declared before using it)
var x int
// Give value to the variable
x = 3
// Short definition using: = Includes variable definition, specifying its type and giving it valu e
y: = 4
// A function that returns two separate values
sum, prod: = learnMultiple (x, y)
// Print and output in a simple and direct
fmt.Println ("sum:", sum, "prod:", prod)
learnTypes ()
}
The function definition can have multiple coefficients and return values. For example, learnMultiple takes the coefficients x and y and returns two sum and prod values ââof type Int.
func learnMultiple (x, y int) (sum, prod int) {
// Separate the returned values ââwith a regular comma
return x + y, x * y
}
Data Types
func learnTypes () {
// Short tariffs usually perform the desired purpose
// Define a text variable using a double quotation mark
str: = "Learn Go!"
// Define a text variable using a single quotation mark
s2: = `A" raw "string literal can include line breaks.`
// Define a variable of type rune which is another name for the type int32 and the variable of this type contains unicode
g: = 'Σ'
// Float
f: = 3.14195
// Definition of Complex Number (Complex)
c: = 3 + 4i
// Define variables using var
var u uint = 7 // natural number (positive integer)
var pi float32 = 22. / 7 // A decimal of 32 bits
// Short definition (byte is another name for uint8)
n: = byte ('\ n')
// Arrays have a fixed and fixed size at compile time
// Defines an int array of 4 elements with an initial value of zero
var a4 [4] int
// Define an array of 3 elements with values ââ3, 1 and 5
a3: = [.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
API Testing and Development with Postman by Dave Westerveld(3616)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2614)
Software Architecture for Busy Developers by Stéphane Eyskens(2320)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1457)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1402)
Cloud Native with Kubernetes by Alexander Raul(1374)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1346)
Software Architecture Patterns for Serverless Systems by John Gilbert(1338)
Practical Node-RED Programming by Taiji Hagino(1336)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1296)
Mastering React Test-Driven Development by Daniel Irvine(1289)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1243)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
