GoLang For DevOps-1
GoLang For DevOps-1
DAY-1
INTRODUCTION TO
GOLANG AND
DEVOPS
Overview of GoLang
@Sandip Das
What is GoLang?
GoLang, also known as Go, is an
open-source programming language
developed by Google. It was created
to address the issues of software
development at Google, and it has
since gained popularity in the broader
software industry.
@Sandip Das
Go History
2007: Development of Go begins at Google, initiated by Robert Griesemer, Rob
Go version 1.0 publicly
announced as open source
programming language
Development of Go begins
at Google
2007
Pike, and Ken Thompson.
2009
2009: Go is publicly announced in November, and version 1.0 is released as an Go Stable version 1.x is
open-source programming language.
Go 1.5 is released with a officially released
2012: Go version 1 is officially released in March, providing a stable foundation complete rewrite of the
for the language.
compiler 2012
2015: Go 1.5 is released in August, featuring a complete rewrite of the 2015 The Go 1.7 release with a
compiler, moving from C to Go.
new compiler back end for
2016: The Go 1.7 release in August includes a new compiler back end for 64-bit
Go 1.8 was released in 64-bit x86 systems
x86 systems, based on static single-assignment form, improving performance. February with improvements
2017: Go 1.8 is released in February, continuing improvements in performance,
in performance, garbage 2016
garbage collection, and the standard library. collection, and the standard lib
2018: Go 1.11, released in August, introduces Go modules, a new dependency 2017
management system that makes dependency version information explicit and Go 1.11 released ,
easier to manage. introduces Go modules
2019: Go 1.13, released in September, includes improvements to Go modules Go 1.13, released, with
2018
and the introduction of error wrapping in the standard library.
improvements in go modules
and error handling
2020: Go 1.15, released in August, focuses on improvements to the toolchain,
Go 1.15, released with
runtime, and libraries, with a significant change being the reduction of the 2019
typical binary size. improvements in toolchain,
runtime, reduced binary size
2021: Go 1.17, released in August, brings changes to the language and
improvements to the core library and toolchain. Go 1.17, released with core
library and tool chain 2020
2022: Go 1.18, introduces generics along with bug fixes and security fixes for Source: Official Go release page
compiler. improvements
2021
2023: Go 1.21 overall language improvements @Sandip Das
Features of GoLang
01 Simplicity and Readability
Go is designed to be simple and easy to understand. Its syntax is clean and concise, which makes it easy to read
and write.
02 Concurrency Support
One of the most notable features of Go is its built-in support for concurrency. Go routines (lightweight threads)
and channels (for communication between Go routines) make concurrent programming more accessible and
efficient.
03 Fast Compilation
Go compiles very quickly, which enhances the productivity of developers. This is partly due to its simplicity and
the way it handles dependencies.
04 Static Typing
Go is statically typed, which means that types are checked at compile time. This can lead to more reliable and
efficient code.
@Sandip Das
Features of GoLang
05 Garbage Collection
It has a powerful garbage collector that helps manage memory automatically, reducing the risk of memory leaks
and other memory-related errors.
06 Standard Library
Go comes with a rich standard library that covers a wide range of functionalities, from handling I/O to
networking.
07 Cross-Platform
Go supports cross-platform development, making it possible to build software that runs on various operating
systems, including Windows, Linux, and macOS.
@Sandip Das
Usecases
01 Web Development
Go is often used for building web servers, RESTful APIs, and microservices due to its efficiency and scalability.
04 Data Processing
Go's performance characteristics make it suitable for data processing tasks that require concurrency and
efficiency.
@Sandip Das
It's time to Install Go
01 Follow Official Installation Instruction
Go to: https://go.dev/doc/install then follow simple
instructions
02 Download Go
download the Go installer from the official Go website: golang.org.
Choose the appropriate version for your operating system. After
downloading follow instructions as per step 1
@Sandip Das
Getting Started...
01 Make Sure You have good An integrated development environment (IDE)!
Good IDE makes life easier, if you are not sure which to choose, here are the most popular for Go:
LiteIDE , Visual Studio Code (VS Code), GoLand, Sublime Text
My personal all-time favorite is VS Code, which you can download from here: https://code.visualstudio.com
import "fmt"
func main() {
fmt.Println("Hello, World!")
} @Sandip Das
Basic GoLang syntax
&
types
@Sandip Das
Basic Syntax
Packages
Every Go file starts with a package declaration, which
provides a way for code to be reused. The main package is
the starting point of a Go program.
Imports
This is where you include code from other packages. The
fmt package, for example, is commonly used for formatted
I/O.
Functions
Functions are declared with the func keyword. The main
function is the entry point of a Go program.
@Sandip Das
Basic Syntax
Variables
Variables can be declared using the var keyword, but Go
also allows for short variable declaration with :=.
Control Structures
Go has control structures like if, for, switch, but no while
or do while.
Error Handling
Go handles errors by returning an error type as a part of
the function's return value.
@Sandip Das
Types
Basic Types
Includes integers (int, uint, int8, uint8, int32, uint32, int64, uint64), floating points (float32, float64), complex numbers
(complex64, complex128), boolean (bool), and string (string).
Composite Types
Arrays:
Fixed-size list of elements of the same type.
Slices:
Dynamically sized, flexible view into the elements of an array.
Structs:
Collection of fields.
Maps:
Collection of key-value pairs.
@Sandip Das
Types
Pointers
Go has pointers, allowing you to pass references to values and records
within your program.
Interfaces
An interface type is defined by a set of methods. A value of interface type
can hold any value that implements those methods.
Functions as Types
Functions can also be used as types, allowing
for higher-order functions.
@Sandip Das
Introduction to
DevOps and its
principles
What is DevOps?
DevOps is a set of practices and philosophies that
aims to unify software development (Dev) and
software operation (Ops).
@Sandip Das
Key Principles of DevOps @Sandip Das
Automation:
Automation is a cornerstone of the DevOps philosophy. This includes automating the integration, testing, deployment, and monitoring of software. Automation helps to increase efficiency,
reduce errors, and speed up the delivery of software.
Microservices Architecture:
Many DevOps teams favor a microservices architecture, which structures an application as a collection of loosely coupled services. This approach enables small, independent teams to develop,
deploy and scale their respective services independently.
@Sandip Das