Introduction to Go (Golang) Programming Language

Introduction

Go is a procedural programming language. It was developed in 2007 by Robert Griesemer, Rob Pike, and Ken Thompson at Google but launched in 2009 as an open-source programming language. Programs are assembled by using packages, for efficient management of dependencies. This language also supports environment adopting patterns alike to dynamic languages. For eg., type inference (y := 0 is a valid declaration of a variable y of type float).

Beginning with Go programming

There are various online IDEs such as The Go Playground, repl.it, etc. which can be used to run Go programs without installing.

For installing Go in own PCs or Laptop we need of following two software: Text editor and Compiler
Text Editor: Text editor gives you a platform where you write your source code. Following are the list of text editors:

  • Windows notepad
  • OS Edit command
  • Brief
  • Epsilon
  • vm or vi
  • Emacs

Finding a Go Compiler: Go distribution comes as a binary installable for FreeBSD (release 8 and above), Linux, Mac OS X (Snow Leopard and above), and Windows operating systems with 32-bit (386) and 64-bit (amd64) x86 processor architectures.
For more instructions about installing. Please visit For installing GO distribution

Note: Extension of source code file of go language must be .go

Writing first program in Go:

package main  
 
import "fmt"

func main() {

     // prints Morioh
     fmt.Println("Hello, Morioh") 
}

Output:

Hello, Morioh

Explanation of the syntax of Go program:

  • Line 1: It contains the package main of the program, which have overall content of the program.It is the initial point to run the program, So it is compulsory to write.
  • Line 2: It contains import “fmt”, it is a preprocessor command which tells the compiler to include the files lying in the package.
  • Line 3: main function, it is beginning of execution of program.
  • Line 4: fmt.Println() is a standard library function to print something as a output on screen.In this, fmt package has transmited Println method which is used to display the output.
  • Comment: Comments are used for explaining code and are used in similar manner as in Java or C or C++. Compilers ignore the comment entries and does not execute them. Comments can be of single line or multiple lines.

Single Line Comment:
Syntax:

// single line comment 

Multi line Comment:
Syntax:

/* multiline comment */

Following is another example:

package main
import "fmt"

func main() {
   fmt.Println("1 + 1 =", 1 + 1)
}

Output:

1 + 1 = 2

Explanation of the above program:
In this above program, the same package line, the same import line, the same function declaration and uses the same Println function as we have used in 1st GO program. This time instead of printing the string “Hello, geeksforgeeks” we print the string 1 + 1 = followed by the result of the expression 1 + 1. This expression is made up of three parts: the numeric literal 1 (which is of type int), the + operator (which represents addition) and another numeric literal 1.

Why this “Go language”?

Because Go language is an effort to combine the ease of programming of an interpreted, dynamically typed language with the efficiency and safety of a statically typed, compiled language. It also aims to be modern, with support for networked and multicore computing.

What excluding in Go which is present in other languages?

  • Go attempts to reduce the amount of typing in both senses of the word. Throughout its design, developers tried to reduce clutter and complexity.
  • There are no forward declarations and no header files; everything is declared exactly once.
  • Stuttering is reduced by simple type derivation using the := declare-and-initialize construct.
  • There is no type hierarchy: types just are, they don’t have to announce their relationships.

Hardware Limitations

We have observed that in a decade, the hardware and processing configuration is changing at a very slow rate. In 2004, P4 was having the clock speed of 3.0 GHz and now in 2018, Macbook pro has the clock speed of Approx (2.3Ghz v 2.66Ghz). To speed up, the functionality we use more processors, but using more processor the cost also increases. And due to this we use limited processors and using limited processor we have a heavy prog. language whose threading takes more memory and slows down the performance of our system, Hence to overcome such problem Golang has been designed in such a way that instead of using threading it uses Goroutine, which is similar to threading but consumes very less memory.
Like threading consumes 1MB whereas Goroutine consumes 2KB of memory, hence at the same time, we can have millions of goroutine triggered.
So the above-discussed point makes golang a strong language that handles concurrency like C++ and Java.

Advantages and Disadvantages of Go Language

Advantages:

  1. Flexible- It is concise, simple and easy to read.
  2. Concurrency- It allows multiple process running simultaneously and effectively.
  3. Quick Outcome- Its compilation time is very fast.
  4. Library- It provide a rich standard library.
  5. Garbage collection- It is a key feature of go. Go excels in giving a lot of control over memory allocation and has dramatically reduced latency in the most recent versions of the garbage collector.
  6. It validates for the interface and type embedding.

Disadvantages:

  1. It has no support for generics, even if there are many discussions about it.
  2. The packages distributed with this programming language is quite useful but Go is not so object-oriented in the conventional sense.
  3. There is absence of some libraries especially a UI tool kit.

Some popular Applications developed in Go Language

  • Docker: a set of tools for deploying linux containers
  • Openshift: a cloud computing platform as a service by Red Hat.
  • Kubernetes: The future of seamlessly automated deployment processes
  • Dropbox: migrated some of their critical components from Python to Go.
  • Netflix: for two part of their server architecture.
  • InfluxDB: is an open-source time series database developed by InfluxData.
  • Golang: The language itself was written in Go.

Features of go language

  • Language Design: The designers of the language made a conscious purposeful to keep the language simple and easy to understand. The entire detailing is in a small number of pages and some interesting design decisions were made through Object-Oriented support in the language.Towards this, the language is opinionated and recommends an idiomatic way of achieving things. It prefers Composition over Inheritance. In Go Language, “Do More with Less” is the mantra.
  • Package Management: Go merges modern day developer workflow of working with Open Source projects and includes that in the way it manages external packages. Support is provided directly in the tooling to get external packages and publish your own packages in a set of easy commands.
  • Powerful standard library: Go has powerful standard library, which is distributed as packages.
  • **Static Typing:**Go is static typed language. So, in this compiler not just work on compiling the code successfully but also ensures on type conversions and compatibility. Because of this feature Go avoid all those problems which we face in dynamically typed languages.
  • Testing Support: Go provides us the unit testing features by itself i.e., a simple mechanism to write your unit test parallel with your code because of this you can understand you code coverage by your own tests. And that can be easily used in generating your code documentation as an example.
  • Platform Independent: Go language is just like Java language as it support platform independency. Due to its modular design and modularity i.e., the code is compiled and is converted into binary form which is as small as possible and hence, it requires no dependency. Its code can be compiled in any platform or any server and application you work on.

#go #golang #webdev

What is GEEK

Buddha Community

Introduction to Go (Golang) Programming Language
Cayla  Erdman

Cayla Erdman

1594369800

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Models for SQL exist. In any case, the SQL that can be utilized on every last one of the major RDBMS today is in various flavors. This is because of two reasons:

1. The SQL order standard is genuinely intricate, and it isn’t handy to actualize the whole standard.

2. Every database seller needs an approach to separate its item from others.

Right now, contrasts are noted where fitting.

#programming books #beginning sql pdf #commands sql #download free sql full book pdf #introduction to sql pdf #introduction to sql ppt #introduction to sql #practical sql pdf #sql commands pdf with examples free download #sql commands #sql free bool download #sql guide #sql language #sql pdf #sql ppt #sql programming language #sql tutorial for beginners #sql tutorial pdf #sql #structured query language pdf #structured query language ppt #structured query language

Zander  Herzog

Zander Herzog

1596793260

Secure HTTPS servers in Go

In this article, we are going to look at some of the basic APIs of the http package to create and initialize HTTPS servers in Go.

Image for post

(source: unsplash.com)

In the “Simple Hello World Server” lesson, we learned about net/http package, how to create routes and how [ServeMux](https://golang.org/pkg/net/http/#ServeMux) works. In the “Running multiple HTTP servers” lesson, we learned about [Server](https://golang.org/pkg/net/http/#Server) structure and how to run multiple HTTP servers concurrently.

In this lesson, we are going to create an HTTPS server using both Go’s standard server configuration and custom configuration (using [_Server_](https://golang.org/pkg/net/http/#Server) structure). But before this, we need to know what HTTPS really is?

HTTPS is a big topic of discussion in itself. Hence while writing this lesson, I published an article just on “How HTTPS works?”. I advise you to read this lesson first before continuing this article. In this article, I’ve also described the encryption paradigm and SSL certificates generation process.


If we recall the simplest HTTP server example from previous lessons, we only need http.``[ListenAndServe](https://golang.org/pkg/net/http/#ListenAndServe) function to start an HTTP server and http.``[HandleFunc](https://golang.org/pkg/net/http/#HandleFunc) to register a response handler for a particular endpoint.

Image for post

(https://play.golang.org/p/t3sOenOYAzS)

In the example above, when we run the command go run server.go , it will start an HTTP server on port 9000. By visiting http://localhost:9000 URL in a browser, you will be able to see a Hello World! message on the screen.

Image for post

(http://localhost:9000)

As we know, the nil argument to ListenAndServe() call invokes Go to use the [DefaultServeMux](https://golang.org/pkg/net/http/#DefaultServeMux) response multiplexer, which is the default instance of ServeMux structure provided globally by the Go. The HandleFunc() call adds a response handler for a specific route on the multiplexer instance.

The http.ListenAndServe() call uses the Go’s standard HTTP server configuration, however, in the previous lesson, how we can customize a server using [Server](https://golang.org/pkg/net/http/#Server) structure type.

To start an HTTPS server, all we need do is to call ServerAndListenTLS method with some configuration. Just like ServeAndListen method, this method is available on both the http package and the Server structure.

The http.``[ServeAndListenTLS](https://golang.org/pkg/net/http/#ListenAndServeTLS) method uses the Go’s standard server implementation, however, both [Server](https://golang.org/pkg/net/http/#Server) instance and Server.``[ServeAndListenTLS](https://golang.org/pkg/net/http/#Server.ListenAndServeTLS) method can be configured for our needs.

#go-programming-language #go #golang-tutorial #go-programming #golang

Learning Go — Array, Slice, Map

We have already seen how to create and work with variables, pointers, and Constants. In this article, we are going to see the four important collection types built into the language.
We start with humble Arrays, from there we move on to Slice, an evolved version of Array. From Slice, we talk about the map a key-value pair collection. Let’s start with Arrays here.

#golang-tutorial #golang #go-programming #go-programming-language #programming

Fannie  Zemlak

Fannie Zemlak

1599854400

What's new in the go 1.15

Go announced Go 1.15 version on 11 Aug 2020. Highlighted updates and features include Substantial improvements to the Go linker, Improved allocation for small objects at high core counts, X.509 CommonName deprecation, GOPROXY supports skipping proxies that return errors, New embedded tzdata package, Several Core Library improvements and more.

As Go promise for maintaining backward compatibility. After upgrading to the latest Go 1.15 version, almost all existing Golang applications or programs continue to compile and run as older Golang version.

#go #golang #go 1.15 #go features #go improvement #go package #go new features

Go Programming

Go Programming

1633663722

Getting Started with Go Programming Language

What is Go? Golang Programming Language Meaning Explained

Go, also known as Golang, is an open-source, compiled, and statically typed programming language designed by Google. It is built to be simple, high-performing, readable, and efficient.

In this article, you'll learn:

  • Where Go came from and where it is now,
  • Why I think you should learn it,
  • How to install and run it on Windows 10, and
  • How to write your first "Hello World" program in Go

Table of Contents

  • What's the Name? Go or Golang?
  • How Go Came into Existence
  • Why you Should Learn Go
  • How to Install and Run Go on Windows 10
  • How to Write your First Hello World in Go
  • Conclusion

What's the Name? Go or Golang?

You might hear the language called both Go and Golang, which might be confusing. I once thought they were names for different languages. But Golang is just another name for Go – and Go remains the official name.

Golang came from the domain name of the Go official website, golang.org. Which is actually really helpful, because “Golang” is much more searchable than "Go" on Google. So it makes life a little easier for those who might be looking for information on the programming language.

How Go Came into Existence

The Go programming language was borne because things were getting much more complex in the codebases within Google.

It was designed by Robert Griesemer, Rob Pike, and Ken Thompson, who all reportedly have a shared dislike for C++.

Go was announced to the public in 2009, and it was made open source in 2012 when its first version, 1.0, was released.

Go quickly rose in popularity and became many developers' first choice due to its simplicity, readability, efficiency, and concurrent nature. Concurrent means that it can run multiple tasks at the same time.

Go is used for server-side (backend) programming, game development, cloud-based programming, and even Data Science. It is also popular for making command-line tools.

Today, many tech giants use Go like Google, Netflix, Twitch, Ethereum, Dropbox, Kubernetes, Docker, Heroku, and lots more.

There’s no surprise that the likes of Kubernetes, Docker, and Heroku are using Go because cloud-based programming is one of the main reasons why Go was designed.

Why you Should Learn Go

Easy Learning Curve

Go is one of the simplest programming languages out there. It is easy to pick up especially if you already have knowledge of any other programming language. In my case, I learned the fundamentals of Go in one sitting.

A lot of developers who use Go and are confident in their teaching abilities say that they can get an absolute beginner to build an app with Go in just a few hours.

The simplicity of Go is one of the main reasons it jumped 5 places from the 10th to 5th most loved programming language according to the 2020 StackOverflow Developer Survey.

Active Community and Good Documentation

Go has solid and easy-to-read documentation. You can read the documentation on the official website.

Apart from documentation, Go also has a supportive and active community behind it, so you can always get help when you are stuck.

The hashtag #golang is commonly used on Twitter, so in case you get stuck, you can tweet your question and attached the hashtag to it.

You Can Get a lot Done with Go

Go is a multipurpose programming language, meaning you can use it for a number of things such as web development, data science, cloud computing, and more.

If you want to have a career in cloud-based programming, you should consider learning Go, because platforms such as Amazon Web Services, Kubernetes, and Google Cloud Platform (GCP) all support Go.

Attractive Wages

According to the 2020 StackOverflow Developer Survey, Go developers are the third-highest paid after Perl and Scala with a median salary of $74K.

This figure will probably continue to climb, because Go continues to gain more popularity every year and it is in demand. So, if you want to earn more money, you should consider learning Go.

How to Install and Run Go on Windows 10

To install Go on your Windows machine, you first have to download Go from the official website. It is available for all popular operating systems. Click on the one that correlates to your OS and install it.

Step 1: Before installing Go, open up your command prompt, type “go” and hit enter. You can open the command prompt by entering “cmd” in the Windows Search bar, and then selecting the first app that shows up.

When you enter “go” and hit enter, you should get a message that says “'go' is not recognized as an internal or external command, operable program or batch file”.

ss-1

Don’t worry, this is because you have to install Go by double-clicking on the Installer downloaded from the Go website.

Step 2: Double-click on the downloaded installer to install Go. Follow the prompts accordingly and Go will be installed.

ss-2
ss-3

Step 3: After installing Go through the installer, head back to the command line and enter “go” again. This time around, you should see several commands available in Go.

ss-4

Step 4: But you can’t just start programming in Go like that. You have to set up your Go workspace by configuring environment variables.

So, head over to your desktop and create the folder “go-workspace”. You can name it whatever you want. This is the folder where your Go projects will be stored. Only when you set the value of the GOPATH variable to it. We do this in the next steps.

Step 5: Search for “env” on the windows Searchbar and click on “Edit the system environment variables”.

ss-5

Step 6: Click on “Environment Variables”.

ss6-edited-1

What you are going to do here is change the value of the GOPATH variable to the folder you created in Step 4.

Step 7: Make sure “GOPATH” is selected, then click “Edit…”.

ss-7edited

Step 8: Click on “Browser Directory”.

ss-8edited

Step 9: Select the folder you created in Step 4. That is, “go-workspace”, or whatever you named it.

ss-9edited

Click “Ok”.

ss-10edited

Click "Ok" again.

ss-11edited

And "Ok" again.

ss-12edited

That’s it! You can now start programming in Go on your Windows machine.

How to Write your First Hello World in Go

Step 1: Open up the “go-workspace” folder (or whatever you named it) with VS Code (or your code editor of choice) and create a file named main.go. You can name the file whatever you want.

ss-13

Step 2: When you hit enter, you will be prompted to install the Go extension for VS Code. Make sure you install it as it will give your code editor some Golang superpowers such as syntax highlighting and snippet suggestions.

You should also be prompted by VS Code to install some more extensions. Install them all. In my case, I installed everything for my VS Code already and all my extensions are in sync, so I didn’t get those prompts.

Paste in the following code in the main.go file (or whatever you named the file):

package main

import "fmt"

func main() {
    fmt.Println("Hello World")
}

What’s the code above doing?

The first line has package main. “package” is a collection of files and code every Go file has. Think of package as a containing folder for your Go files and codes.

No matter what you named your file, make sure the “package main” is available on top of your code.

After that fmt gets brought in. “fmt” is a package from the Go standard library. It is used for formatting strings and printing messages to the command line. It contains methods for doing things in Go.

One of the methods is Println, meaning “print line”, which we will use to print our “Hello World” text.

Inside the function “main”, the fmt package was then used to output our “Hello World” text to the console.

To run this code, open up your terminal, type go run main.go, and hit enter. If you named your file something else, make it go run yourFileName.go.

ss-14

Conclusion

In this article, you learned about the Go programming language and why it is a good one to know. You also learned how to install Go on a Windows machine and write your first Hello World program in it.

Go is a powerful programming language that is here to stay. It's clear from the 2020 StackOverflow Developer Survey that developers love Go, and its popularity is rising year by year.

Go is definitely worth your time. Now, go learn some Go.

Original article source at https://www.freecodecamp.org

#go #golang #programming #develope