SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
EQUALEYES BLOG
Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month!
Beginning development in Go
Zan Skamljic
EQUALEYES BLOG
Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month!
I have heard of Go, but what is it really?
Go (sometimes referred to as “golang”) is a programming language developed by Google. If that did not
get your attention, maybe the co-author will: Ken Thompson. He implemented both Unix and the B
programming language, which was a direct predecessor of C. Go is a compiled language, using a garbage
collector. The compiler and other Go tools are all free and open source. Its compiler is self-hosting,
meaning the compiler and the tools themselves are written in Go. Go is supposed to be simple, lightweight
and clean. It only has 25 keywords!
Ok, but why should I consider trying Go?
For me, it was the cross-platform development. Go can be build for multiple architectures, multiple OS-
es in a single line. For example, a developer on a Linux machine can easily build a Windows or macOS
executable without any hassle, for example “GOOS=windows GOARCH=amd64 go build”. The GOARCH
variable only needs to be present if we’re building for a different architecture than the machine we’re
developing on, for example arm.
When building an executable, you will notice that it is bigger than usual executables. That’s because the
file is compiled as a monolithic executable. This means that the file will contain every single dependency
it needs. Essentially, this means that it won’t need any so/dll/dylib files. It creates a dependency free
executable, no need to install anything or have more than one file to copy and run!
The language has a great multi-threading concept called “goroutines”. A goroutine is a function call,
preceded by the “go” keyword. It spawns a lightweight thread in which that function is executed at almost
zero cost.
Another great feature is formatting. Many languages lack a proper formatting tool and many times they
ignore the code style altogether. Go is slightly different. The style is uniform across all applications, so
every source file is formatted the same. Several ways to format the code may also report compile-time
errors, which may seem like a downside at first, but it forces you to write readable code.
When you install Go, the tooling comes with a compiler, code formatter, package manager, and a testing
framework. This basically means that majority of tasks are as simple as running for example “go build” for
building a project, “go get” to download dependencies and “go test” to run tests.
OK, I’m sold. How do I start?
Pick your favourite editor or IDE, it probably already has a plugin for Go. If you can’t decide I would suggest
either GoLand (by JetBrains), Visual Studio Code (with Go plugin) or if you’re feeling hardcore, vim with
vim-go plugin. The installers for Go are available at https://golang.org/dl/. If you’re using Linux, the
package is probably in your repositories, so you can just use your package manager to install it (sudo apt
install go, yum install go, pacman -S go, …). The example hello world follows:
EQUALEYES BLOG
Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month!
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}
Let’s save that as “main.go”. To run it we can use the terminal command “go run” (which basically
compiles and runs the code in current directory, neat, right?). If we wanted to build an executable we
could run “go build” instead. I believe the code here should be pretty self-explanatory: we declare that
our file belongs to package main (which is the default go package), import the “fmt” package, which
contains functions for formatting strings and basic I/O. The “fmt.Println()” call basically means “call Println
from package fmt”.
How about something more complex?
Let’s create a simple HTTP server. It may sound like a lot of work, but Go has an extensive standard library,
which contains most things you’d need a third party library for in other languages. Here’s the code that
runs a http server, listening on port 8080, returning the “Hello world” message:
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello world!")
})
http.ListenAndServe(":8080", nil)
}
Impressive, isn’t it? Now naturally, there’s a way to route to multiple endpoints and filter the calls based
on the request method, but that’s a topic for another time.
EQUALEYES BLOG
Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month!
How about OOP?
OOP in Go is slightly different to what you might be used to, in fact it’s probably mostly similar to C (not
C++!). Anyone with experience in C development will notice that OOP works mostly in the same way, but
with several improvements. Let’s take a look:
type User struct {
Name string `json:"first_name"`
age int `json:"age"`
}
func (u User) PrintHello() {
fmt.Printf("Hello %sn", u.Name)
}
func (u *User) SetAge(age int) {
u.Age = age
}
// ...
user.PrintHello()
user.SetAge(23)
// ...
The code here defines a structure User, with a public field “Name” and a private field age. “But how can
you tell?” you may ask. Simple. All names in lowercase are package-private and the uppercase names are
public. We’ve also declared two functions. Notice the thing on the left of the function name? It’s called a
receiver. It can be either a pointer or a regular variable. The pointer is used when you want the function
to mutate the object or if you want to avoid copying the object. Notice that both the pointer and regular
references access the function and variables without ever using the arrow (“->”) operator like in C. You’ve
also probably noticed the “`json:"first_name"`”. These are called tags. They are accessible at runtime using
reflection, should you need them. In our case they can be used to serialize the User object to json, using
EQUALEYES BLOG
Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month!
the standard library, with the names specified in the tags. Similarly, we can also use tags to associate fields
with column names in a database for ORMs, xml serialization and many more.
How about performance?
Since Go is a compiled language it is a lot faster than the scripting languages like Node.js, Python etc. In
fact, Go is very close to C/C++ when it comes to performance (even though it offers access to runtime
reflection and a garbage collector). For example here are some sample benchmarks for Go: Go vs C, Go
vs C++, Go vs Node.js.
That’s all for now, I hope it made you consider using Go in one of your future projects.

Weitere ähnliche Inhalte

Was ist angesagt?

Running a Plone product on Substance D
Running a Plone product on Substance DRunning a Plone product on Substance D
Running a Plone product on Substance DMakina Corpus
 
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageJohn Potocny
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go langAmal Mohan N
 
Go Programming Language by Google
Go Programming Language by GoogleGo Programming Language by Google
Go Programming Language by GoogleUttam Gandhi
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to GoOliver N
 
Messing with binary formats
Messing with binary formatsMessing with binary formats
Messing with binary formatsAnge Albertini
 
An introduction to go programming language
An introduction to go programming languageAn introduction to go programming language
An introduction to go programming languageTechnology Parser
 
Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Codemotion
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventuremylittleadventure
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golangBasil N G
 
Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scriptingArghodeepPaul
 
E-books and App::Pod2Epub
E-books and App::Pod2EpubE-books and App::Pod2Epub
E-books and App::Pod2EpubSøren Lund
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programmingExotel
 
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017Codemotion
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with GolangTakaaki Mizuno
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)Eric Johnson
 

Was ist angesagt? (20)

Go lang
Go langGo lang
Go lang
 
Running a Plone product on Substance D
Running a Plone product on Substance DRunning a Plone product on Substance D
Running a Plone product on Substance D
 
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming LanguageATO 2014 - So You Think You Know 'Go'? The Go Programming Language
ATO 2014 - So You Think You Know 'Go'? The Go Programming Language
 
Introduction to go lang
Introduction to go langIntroduction to go lang
Introduction to go lang
 
Php test fest
Php test festPhp test fest
Php test fest
 
Go Programming Language by Google
Go Programming Language by GoogleGo Programming Language by Google
Go Programming Language by Google
 
Golang #5: To Go or not to Go
Golang #5: To Go or not to GoGolang #5: To Go or not to Go
Golang #5: To Go or not to Go
 
Messing with binary formats
Messing with binary formatsMessing with binary formats
Messing with binary formats
 
An introduction to go programming language
An introduction to go programming languageAn introduction to go programming language
An introduction to go programming language
 
Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017Getting started with Go - Florin Patan - Codemotion Rome 2017
Getting started with Go - Florin Patan - Codemotion Rome 2017
 
The Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventureThe Go programming language - Intro by MyLittleAdventure
The Go programming language - Intro by MyLittleAdventure
 
Windows script host
Windows script hostWindows script host
Windows script host
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
Windows batch scripting
Windows batch scriptingWindows batch scripting
Windows batch scripting
 
E-books and App::Pod2Epub
E-books and App::Pod2EpubE-books and App::Pod2Epub
E-books and App::Pod2Epub
 
Introduction to Go programming
Introduction to Go programmingIntroduction to Go programming
Introduction to Go programming
 
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
Golang and Domain Specific Languages - Lorenzo Fontana - Codemotion Rome 2017
 
Cpb2010
Cpb2010Cpb2010
Cpb2010
 
Building Command Line Tools with Golang
Building Command Line Tools with GolangBuilding Command Line Tools with Golang
Building Command Line Tools with Golang
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)
 

Ähnlich wie Beginning development in go

Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageGanesh Samarthyam
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Codemotion
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to GoSimon Hewitt
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Ganesh Samarthyam
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in GoAmr Hassan
 
Advantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworksAdvantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworksKaty Slemon
 
Scaling applications with go
Scaling applications with goScaling applications with go
Scaling applications with goVimlesh Sharma
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01Getachew Ganfur
 
Cross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn UstepCross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn Ustepwangii
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it securityCESAR A. RUIZ C
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)Jorge López-Lago
 
Resources For Floss Projects
Resources For Floss ProjectsResources For Floss Projects
Resources For Floss ProjectsJon Spriggs
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageAniruddha Chakrabarti
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming languageMario Castro Contreras
 
Java And Community Support
Java And Community SupportJava And Community Support
Java And Community SupportWilliam Grosso
 
The Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundThe Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundRodolfo Carvalho
 

Ähnlich wie Beginning development in go (20)

Let's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming LanguageLet's Go: Introduction to Google's Go Programming Language
Let's Go: Introduction to Google's Go Programming Language
 
Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016Getting started with go - Florin Patan - Codemotion Milan 2016
Getting started with go - Florin Patan - Codemotion Milan 2016
 
Introduction to Go
Introduction to GoIntroduction to Go
Introduction to Go
 
Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction Google's Go Programming Language - Introduction
Google's Go Programming Language - Introduction
 
Go programing language
Go programing languageGo programing language
Go programing language
 
Introduction to Programming in Go
Introduction to Programming in GoIntroduction to Programming in Go
Introduction to Programming in Go
 
Advantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworksAdvantages of golang development services & 10 most used go frameworks
Advantages of golang development services & 10 most used go frameworks
 
Scaling applications with go
Scaling applications with goScaling applications with go
Scaling applications with go
 
C++ for hackers
C++ for hackersC++ for hackers
C++ for hackers
 
His162013 140529214456-phpapp01
His162013 140529214456-phpapp01His162013 140529214456-phpapp01
His162013 140529214456-phpapp01
 
Cross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn UstepCross Platform Objective C Development Using Gn Ustep
Cross Platform Objective C Development Using Gn Ustep
 
C plus plus for hackers it security
C plus plus for hackers it securityC plus plus for hackers it security
C plus plus for hackers it security
 
Opensource Software usability
Opensource Software usabilityOpensource Software usability
Opensource Software usability
 
Open event (show&tell april 2016)
Open event (show&tell april 2016)Open event (show&tell april 2016)
Open event (show&tell april 2016)
 
Resources For Floss Projects
Resources For Floss ProjectsResources For Floss Projects
Resources For Floss Projects
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
Introduction to Google's Go programming language
Introduction to Google's Go programming languageIntroduction to Google's Go programming language
Introduction to Google's Go programming language
 
Scripting in OpenOffice.org
Scripting in OpenOffice.orgScripting in OpenOffice.org
Scripting in OpenOffice.org
 
Java And Community Support
Java And Community SupportJava And Community Support
Java And Community Support
 
The Go features I can't live without, 2nd round
The Go features I can't live without, 2nd roundThe Go features I can't live without, 2nd round
The Go features I can't live without, 2nd round
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 

Kürzlich hochgeladen (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 

Beginning development in go

  • 1. EQUALEYES BLOG Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month! Beginning development in Go Zan Skamljic
  • 2. EQUALEYES BLOG Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month! I have heard of Go, but what is it really? Go (sometimes referred to as “golang”) is a programming language developed by Google. If that did not get your attention, maybe the co-author will: Ken Thompson. He implemented both Unix and the B programming language, which was a direct predecessor of C. Go is a compiled language, using a garbage collector. The compiler and other Go tools are all free and open source. Its compiler is self-hosting, meaning the compiler and the tools themselves are written in Go. Go is supposed to be simple, lightweight and clean. It only has 25 keywords! Ok, but why should I consider trying Go? For me, it was the cross-platform development. Go can be build for multiple architectures, multiple OS- es in a single line. For example, a developer on a Linux machine can easily build a Windows or macOS executable without any hassle, for example “GOOS=windows GOARCH=amd64 go build”. The GOARCH variable only needs to be present if we’re building for a different architecture than the machine we’re developing on, for example arm. When building an executable, you will notice that it is bigger than usual executables. That’s because the file is compiled as a monolithic executable. This means that the file will contain every single dependency it needs. Essentially, this means that it won’t need any so/dll/dylib files. It creates a dependency free executable, no need to install anything or have more than one file to copy and run! The language has a great multi-threading concept called “goroutines”. A goroutine is a function call, preceded by the “go” keyword. It spawns a lightweight thread in which that function is executed at almost zero cost. Another great feature is formatting. Many languages lack a proper formatting tool and many times they ignore the code style altogether. Go is slightly different. The style is uniform across all applications, so every source file is formatted the same. Several ways to format the code may also report compile-time errors, which may seem like a downside at first, but it forces you to write readable code. When you install Go, the tooling comes with a compiler, code formatter, package manager, and a testing framework. This basically means that majority of tasks are as simple as running for example “go build” for building a project, “go get” to download dependencies and “go test” to run tests. OK, I’m sold. How do I start? Pick your favourite editor or IDE, it probably already has a plugin for Go. If you can’t decide I would suggest either GoLand (by JetBrains), Visual Studio Code (with Go plugin) or if you’re feeling hardcore, vim with vim-go plugin. The installers for Go are available at https://golang.org/dl/. If you’re using Linux, the package is probably in your repositories, so you can just use your package manager to install it (sudo apt install go, yum install go, pacman -S go, …). The example hello world follows:
  • 3. EQUALEYES BLOG Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month! package main import "fmt" func main() { fmt.Println("Hello world") } Let’s save that as “main.go”. To run it we can use the terminal command “go run” (which basically compiles and runs the code in current directory, neat, right?). If we wanted to build an executable we could run “go build” instead. I believe the code here should be pretty self-explanatory: we declare that our file belongs to package main (which is the default go package), import the “fmt” package, which contains functions for formatting strings and basic I/O. The “fmt.Println()” call basically means “call Println from package fmt”. How about something more complex? Let’s create a simple HTTP server. It may sound like a lot of work, but Go has an extensive standard library, which contains most things you’d need a third party library for in other languages. Here’s the code that runs a http server, listening on port 8080, returning the “Hello world” message: func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello world!") }) http.ListenAndServe(":8080", nil) } Impressive, isn’t it? Now naturally, there’s a way to route to multiple endpoints and filter the calls based on the request method, but that’s a topic for another time.
  • 4. EQUALEYES BLOG Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month! How about OOP? OOP in Go is slightly different to what you might be used to, in fact it’s probably mostly similar to C (not C++!). Anyone with experience in C development will notice that OOP works mostly in the same way, but with several improvements. Let’s take a look: type User struct { Name string `json:"first_name"` age int `json:"age"` } func (u User) PrintHello() { fmt.Printf("Hello %sn", u.Name) } func (u *User) SetAge(age int) { u.Age = age } // ... user.PrintHello() user.SetAge(23) // ... The code here defines a structure User, with a public field “Name” and a private field age. “But how can you tell?” you may ask. Simple. All names in lowercase are package-private and the uppercase names are public. We’ve also declared two functions. Notice the thing on the left of the function name? It’s called a receiver. It can be either a pointer or a regular variable. The pointer is used when you want the function to mutate the object or if you want to avoid copying the object. Notice that both the pointer and regular references access the function and variables without ever using the arrow (“->”) operator like in C. You’ve also probably noticed the “`json:"first_name"`”. These are called tags. They are accessible at runtime using reflection, should you need them. In our case they can be used to serialize the User object to json, using
  • 5. EQUALEYES BLOG Follow Equaleyes on social media and join our newsletter for fresh articles on tech and startups every month! the standard library, with the names specified in the tags. Similarly, we can also use tags to associate fields with column names in a database for ORMs, xml serialization and many more. How about performance? Since Go is a compiled language it is a lot faster than the scripting languages like Node.js, Python etc. In fact, Go is very close to C/C++ when it comes to performance (even though it offers access to runtime reflection and a garbage collector). For example here are some sample benchmarks for Go: Go vs C, Go vs C++, Go vs Node.js. That’s all for now, I hope it made you consider using Go in one of your future projects.