SlideShare a Scribd company logo
#CLUS
Patrick Riel, Engineer
Stève Sfartz, API Evangelist
DEVNET-1808
#golang for ITPros
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
/Cisco/DevNet/SteveSfartz
• API Evangelist @CiscoDevNet
• API Design,Architecture and Operations
• WebexTeams & Devices/xAPI developer
• hosted @CiscoROI: Paris Innovation Center
• Node.js mainly, a bit of #golang
• Europe and all over the world
• github: //ObjectIsAdvantag
DEVNET-1808
“vision without
execution is
hallucination”
-- Thomas Edison
mailto: stsfartz@cisco.com
twitter: @SteveSfartz
Agenda
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
• Why go?
• HelloWorld: install, code, compile,
test
• Multi-platform builds and
packaging with docker
• Setting up your development
environment
• Walkthrough: creating a command
line interface
• More advanced concepts:
channels, go routines, …
DEVNET-1808 3
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Why Go?
• Released by Google in 2009
• conceived in ‘07, popular since ‘15
• Designed to address software engineering issues faced in the construction
of large server software
• Influenced by: C, Python, Smalltalk,Alef, CSP, Modula, Pascal…
• Focus on clarity, simplicity and composability, resulting in a productive, fun,
expressive and powerful language
• No class inheritance. ‘Embedding’ & ‘Interfaces’ to provide polymorphism
• Built-in parallelism & asynchrony via ‘Channels’ & ‘goroutines’
• Includes a - debugging, profiling, formatting and testing - toolset
4DEVNET-1808
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Software engineering guided the design of Go
https://talks.golang.org/2012/splash.article
• Clear dependencies
• Clear syntax
• Clear semantics
• Composition over inheritance
• Simplicity provided by the programming model (garbage collection,
concurrency)
• Easy tooling (the go tool, gofmt, godoc, gofix)
• TRY IT: https://tour.golang.org
5DEVNET-1808
GoTour
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 7DEVNET-1808
Variables
https://tour.golang.org/basics
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 8DEVNET-1808
Functions: mutiple results
https://tour.golang.org/basics/6
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 9DEVNET-1808
Functions: named results
https://tour.golang.org/basics/7
Setting up Go
on your machine
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Installing Go
https://golang.org/doc/install
• Download the PKG on Mac (or MSI forWindows), and Install
• by default installs in /usr/local/go (or c:Go forWindows).
• adds the Go binary to your PATH environment variable
• Set the GOROOT env variable if you install to a different location
• Type ‘go version’ to check your installation is successful
• Create a ‘go’ workspace directory
• under $HOME/go on Mac (or %USERPROFILE%go forWindows)
• Set a GOPATH environment variable is preferable (and mandatory if
elsewhere)
• Add the $GOPATH/bin directory to your path
11DEVNET-1808
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
HelloWorld (on a Mac)
• Create a “src/hello” directory in your
workspace
• Create a file named hello.go
• Build it with the go tool
• Produces an executable named hello
• Run go install to install the binary into
your workspace's bin directory or go
clean to remove it.
12DEVNET-1808
1
File: src/hello/hello.go
2
3
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
HelloWorld (on Windows)
• Create a “src/hello” directory in your
workspace
• Create a file named hello.go
• Build it with the go tool
• Produces an executable named
hello.exe
• Run go install to install the binary into
your workspace's bin directory or go
clean to remove it.
13DEVNET-1808
1
2
File: src/hello/hello.go
3
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Typical go folder structure
https://golang.org/doc/code.html
• go tooling requires to organize your code in a
specific way
• Go programmers typically keep all their Go code in a
single workspace.
• A workspace contains many version control
repositories (managed by git, for example).
• Each repository contains one or more packages.
• Each package consists of one or more Go source files in
a single directory.
• The path to a package's directory determines its import
path.
14DEVNET-1808
GOPATH = C:Localgowork
mkdir ‘$GOPATH/src/github.com/<username>/hello’
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Creating a Library
https://golang.org/doc/code.html
> mkdir $GOPATH/src/github.com/<user>/hello
15DEVNET-1808
filename: hello.go
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Creating a Library
https://golang.org/doc/code.html
> mkdir $GOPATH/src/github.com/<user>/stringutil
16DEVNET-1808
filename: reverse.go
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Creating a Library
https://golang.org/doc/code.html
> go install github.com/<user>/hello
• the ‘stringutil’ package is automatically installed as well
• go executables are statically linked
17DEVNET-1808
Setting up your
development environment
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Go Extension forVisual Studio Code
19DEVNET-1808
Installs automatically at launch
or manually via go get –v:
github.com/nsf/gocode
github.com/uudashr/gopkgs/cmd/gopkgs
github.com/ramya-rao-a/go-outline
github.com/acroca/go-symbols
golang.org/x/tools/cmd/guru
golang.org/x/tools/cmd/gorename
github.com/fatih/gomodifytags
github.com/haya14busa/goplay/cmd/goplay
github.com/josharian/impl
github.com/rogpeppe/godef
golang.org/x/tools/cmd/godoc
sourcegraph.com/sqs/goreturns
github.com/golang/lint/golint
github.com/cweill/gotests
github.com/derekparker/delve/cmd/dlv
golang.org/x/tools/cmd/guru
Demo
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
VS Code golang extension: InstallationTips
• If any go tools dependency is missing, install it manually
• Make sure the $GOPATH/bin directory appears in your path
• To install the Delve debugger, type
> go get -u github.com/derekparker/delve/cmd/dlv
• If having issue with the debugger on Mac: ‘lldb-server’ not found, type
> xcode-select –install
21DEVNET-1808
Deployment
& Packaging
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Packaging for various platforms
• The go toolchain natively cross-build executables for any Go-supported
foreign platform
• Example:
> env GOOS=linuxGOARCH=amd64 go build
-o dist/demo.linux -v main.go
https://www.digitalocean.com/community/tutorials/how-to-build-go-executables-
for-multiple-platforms-on-ubuntu-16-04
DEVNET-1808
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS DEVNET-1808
Dockerfile example
https://github.com/ObjectIsAdvantag/CLEUR-1814/tree/master/8-docker
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 25DEVNET-1808
Pointers
https://tour.golang.org/moretypes/1
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 26DEVNET-1808
readword.go
CLI with golang
doing chatops
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Methods and Interfaces
• Remember: a method is just a function with a receiver argument
• To implement an interface inGo
• Implement all the methods in the interface
28DEVNET-1808
https://tour.golang.org/methods
https://gobyexample.com/interfaces
https://github.com/ObjectIsAdvantag/CLEUR-1814/blob/master/7-spark/main.go
https://github.com/ObjectIsAdvantag/CLEUR-1814/blob/master/6-interfaces/main.go
CLI Demo
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 30DEVNET-1808
Defer
https://tour.golang.org/flowcontrol/12
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Defer
• defers the execution of a function until the surrounding function returns
• deferred function calls are pushed onto a stack (executed in LIFO)
31DEVNET-1808
counting
done
5
4
3
2
1
0
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
HTTP API Clients
• simplify development
• speed up development
• clean code
• abstraction
https://www.scaledrone.com/blog/posts/creating-an-api-client-in-go
32DEVNET-1808
Advanced #golang
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 34DEVNET-1808
Concurrency: channels & go routines
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 35DEVNET-1808
Structures
https://tour.golang.org/moretypes/2
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 36DEVNET-1808
Arrays
https://tour.golang.org/moretypes/6
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 37DEVNET-1808
Slices
https://tour.golang.org/moretypes/13
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 38DEVNET-1808
Maps
https://tour.golang.org/moretypes/22
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 39DEVNET-1808
Closures
https://tour.golang.org/moretypes/25
Wrapup
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Wrapup… go for ITPros
 CLI
 Proxy
 Reverse Proxy
 Web API
41DEVNET-1808
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
State of go – 2017 user survey
• Continued growth in the language
• Enterprise-ready: for the first time, more Go at work than home
• Top-uses of Go is now writingAPI/RPC services
• 2016 was stillCLI. Now taking advantage of the distinguishing features of Go, key
elements of cloud computing
• Biggest challenges: lack of dependency management, generics
• 64% responses use Go on Linux, 49% on MacOS, 18% onWindows
• VSCode is now the most popular editor for Go developers
• Finding answers:Go website, Stack Overflow, and reading code
• Primary news sources: Go blog, Reddit, andTwitter
42DEVNET-1808
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Cisco Community Contributions
• golang samples
• https://github.com/ObjectIsAdvantag/CLEUR-1814
• Cisco Spark REST API wrapper
• https://github.com/jbogarin/go-cisco-spark
• CiscoACI from golang
• https://github.com/udhos/acigo
• Answering Machine backed byTropo
• https://github.com/ObjectIsAdvantag/answering-machine
• Proxy incoming web hooks to established web sockets
• https://github.com/sgrimee/whproxy
43DEVNET-1808
Complete your online session evaluation
© 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS
Give us your feedback to be entered into a
Daily Survey Drawing.
Complete your session surveys through the
Cisco Live mobile app or on
www.CiscoLive.com/us.
Don’t forget: Cisco Live sessions will be available for viewing on
demand after the event at www.CiscoLive.com/Online.
DEVNET-1808
Q&A
Thank you
#CLUS
#CLUS

More Related Content

PPTX
drone continuous Integration
PDF
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
PDF
Introduction to GitHub Actions
PDF
How to integrate front end tool via gruntjs
PPTX
Gorush: A push notification server written in Go
PDF
2014-11-11 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Seattle
PPTX
Write microservice in golang
PDF
2014-08-19 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Chicago
drone continuous Integration
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
Introduction to GitHub Actions
How to integrate front end tool via gruntjs
Gorush: A push notification server written in Go
2014-11-11 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Seattle
Write microservice in golang
2014-08-19 Multiple Approaches to Managing Puppet Modules @ Puppet Camp Chicago

What's hot (20)

PDF
Automatisation in development and testing - within budget [IronCamp prague 20...
PPTX
Open Source, Sourceforge Projects, & Apache Foundation
PDF
Git, CMake, Conan - How to ship and reuse our C++ projects?
PDF
Moderne Android Builds mit Gradle
PPTX
Open Source, Sourceforge Projects, & Apache Foundation
PDF
13 practical tips for writing secure golang applications
PDF
Drone CI/CD Platform
PDF
Installation and setup hadoop published
PDF
Drone 1.0 Feature
PDF
Badge Poser v3.0 - A DevOps Journey
PDF
Continuous Delivery com Docker, OpenShift e Jenkins
PDF
Continuous Delivery in OSS using Shipkit.org
PDF
Php Dependency Management with Composer ZendCon 2017
PDF
Getting out of the Job Jungle with Jenkins
PDF
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
PDF
Nebula: Netflix's OSS Gradle Plugins
PDF
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
PPTX
GitFlow, SourceTree and GitLab
PDF
Rest, sockets em golang
PDF
GCE 上搭配 Cloud Storage 建置 Drone CI
Automatisation in development and testing - within budget [IronCamp prague 20...
Open Source, Sourceforge Projects, & Apache Foundation
Git, CMake, Conan - How to ship and reuse our C++ projects?
Moderne Android Builds mit Gradle
Open Source, Sourceforge Projects, & Apache Foundation
13 practical tips for writing secure golang applications
Drone CI/CD Platform
Installation and setup hadoop published
Drone 1.0 Feature
Badge Poser v3.0 - A DevOps Journey
Continuous Delivery com Docker, OpenShift e Jenkins
Continuous Delivery in OSS using Shipkit.org
Php Dependency Management with Composer ZendCon 2017
Getting out of the Job Jungle with Jenkins
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
Nebula: Netflix's OSS Gradle Plugins
Analysis of-quality-of-pkgs-in-packagist-univ-20171024
GitFlow, SourceTree and GitLab
Rest, sockets em golang
GCE 上搭配 Cloud Storage 建置 Drone CI
Ad

Similar to Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808 (20)

PPTX
Intro to Git Devnet-1080 Cisco Live 2018
PPTX
Integrated, Automated Video Room Systems - Webex Devices - Cisco Live Orlando...
PDF
DevFest 2022 - Cloud Workstation Introduction TaiChung
PDF
DevOps Bootcamp course resource (1)-1-99.pdf
PPTX
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
PDF
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
PDF
Dependencies Managers in C/C++. Using stdcpp 2014
PPTX
drupal ci cd concept cornel univercity.pptx
PDF
LicensePlist - A license list generator of all your dependencies for iOS appl...
PDF
The Telegraf Toolbelt: It Can Do That, Really? | David McKay | InfluxData
PDF
The Telegraf Toolbelt | David McKay | InfluxData
PDF
Webex Devices xAPI - DEVNET_2071 - Cisco Live - San Diego 2019
PPT
Open up your platform with Open Source and GitHub
PDF
Docman - The swiss army knife for Drupal multisite docroot management and dep...
PDF
Gitlab ci, cncf.sk
PDF
Set up a Development Environment in 5 Minutes
PDF
Improve your Java Environment with Docker
PDF
OSMC 2019 | The Telegraf Toolbelt: It Can Do That, Really? by David McKay
PDF
Go dla elektronika
PPTX
Developing with the Go client for Apache Kafka
Intro to Git Devnet-1080 Cisco Live 2018
Integrated, Automated Video Room Systems - Webex Devices - Cisco Live Orlando...
DevFest 2022 - Cloud Workstation Introduction TaiChung
DevOps Bootcamp course resource (1)-1-99.pdf
Webex Teams Widgets Technical Drill down - Cisco Live Orlando 2018 - DEVNET-3891
[EXTENDED] Ceph, Docker, Heroku Slugs, CoreOS and Deis Overview
Dependencies Managers in C/C++. Using stdcpp 2014
drupal ci cd concept cornel univercity.pptx
LicensePlist - A license list generator of all your dependencies for iOS appl...
The Telegraf Toolbelt: It Can Do That, Really? | David McKay | InfluxData
The Telegraf Toolbelt | David McKay | InfluxData
Webex Devices xAPI - DEVNET_2071 - Cisco Live - San Diego 2019
Open up your platform with Open Source and GitHub
Docman - The swiss army knife for Drupal multisite docroot management and dep...
Gitlab ci, cncf.sk
Set up a Development Environment in 5 Minutes
Improve your Java Environment with Docker
OSMC 2019 | The Telegraf Toolbelt: It Can Do That, Really? by David McKay
Go dla elektronika
Developing with the Go client for Apache Kafka
Ad

More from Cisco DevNet (20)

PDF
DEVNET-2138 - Managing OpenAPI Documents at Scale - clus24.pdf
PPTX
18 facets of the OpenAPI specification - Cisco Live US 2023
PDF
The 12 facets of the OpenAPI standard.pdf
PPTX
the 12 facets of OpenAPI
PPTX
Webex APIs for Administrators - CL20B - DEVNET-2610
PPTX
Advanced coding & deployment for Cisco Video Devices - CL20B - DEVNET-3244
PPTX
Customizing Cisco Collaboration Devices - CL20B - DEVNET-2071
PDF
Webex APIs for Administrators - DEVNET_2610 - Cisco Live 2019
PPTX
Javascript Essentials - Cisco Live Barcelona 2019
PDF
when Apps meet Infrastructure - CodeMotionMilan2018 Keynote - Cisco DevNet - ...
PPTX
Meeting rooms are talking. Are you listening
PPTX
DevNetCreate Workshop - build a react app - React crash course
PPTX
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
PPTX
Meeting rooms are talking! are you listening?
PDF
Emulators as an Emerging Best Practice for API Providers
PPTX
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
PPTX
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
PPTX
Webex APIs for Admins - Cisco Live Orlando 2018 - DEVNET-3610
PPTX
Embedding Messages and Video Calls in your apps
PPTX
BotCommons: Metadata for Bots - Devoxx 2017
DEVNET-2138 - Managing OpenAPI Documents at Scale - clus24.pdf
18 facets of the OpenAPI specification - Cisco Live US 2023
The 12 facets of the OpenAPI standard.pdf
the 12 facets of OpenAPI
Webex APIs for Administrators - CL20B - DEVNET-2610
Advanced coding & deployment for Cisco Video Devices - CL20B - DEVNET-3244
Customizing Cisco Collaboration Devices - CL20B - DEVNET-2071
Webex APIs for Administrators - DEVNET_2610 - Cisco Live 2019
Javascript Essentials - Cisco Live Barcelona 2019
when Apps meet Infrastructure - CodeMotionMilan2018 Keynote - Cisco DevNet - ...
Meeting rooms are talking. Are you listening
DevNetCreate Workshop - build a react app - React crash course
Advanced Postman for Better APIs - Web Summit 2018 - Cisco DevNet
Meeting rooms are talking! are you listening?
Emulators as an Emerging Best Practice for API Providers
Microservices & Serverless Architecture Principles Applied - Cisco Live Orlan...
Chatbots 101: design, code, deploy - Cisco Live Orlando 2018 - DEVNET-2896
Webex APIs for Admins - Cisco Live Orlando 2018 - DEVNET-3610
Embedding Messages and Video Calls in your apps
BotCommons: Metadata for Bots - Devoxx 2017

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
ai tools demonstartion for schools and inter college
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Design an Analysis of Algorithms II-SECS-1021-03
wealthsignaloriginal-com-DS-text-... (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
Wondershare Filmora 15 Crack With Activation Key [2025
How Creative Agencies Leverage Project Management Software.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Understanding Forklifts - TECH EHS Solution
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
ai tools demonstartion for schools and inter college
How to Choose the Right IT Partner for Your Business in Malaysia
VVF-Customer-Presentation2025-Ver1.9.pptx
Transform Your Business with a Software ERP System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

Golang 101 for IT-Pros - Cisco Live Orlando 2018 - DEVNET-1808

  • 1. #CLUS Patrick Riel, Engineer Stève Sfartz, API Evangelist DEVNET-1808 #golang for ITPros
  • 2. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS /Cisco/DevNet/SteveSfartz • API Evangelist @CiscoDevNet • API Design,Architecture and Operations • WebexTeams & Devices/xAPI developer • hosted @CiscoROI: Paris Innovation Center • Node.js mainly, a bit of #golang • Europe and all over the world • github: //ObjectIsAdvantag DEVNET-1808 “vision without execution is hallucination” -- Thomas Edison mailto: stsfartz@cisco.com twitter: @SteveSfartz
  • 3. Agenda © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS • Why go? • HelloWorld: install, code, compile, test • Multi-platform builds and packaging with docker • Setting up your development environment • Walkthrough: creating a command line interface • More advanced concepts: channels, go routines, … DEVNET-1808 3
  • 4. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Why Go? • Released by Google in 2009 • conceived in ‘07, popular since ‘15 • Designed to address software engineering issues faced in the construction of large server software • Influenced by: C, Python, Smalltalk,Alef, CSP, Modula, Pascal… • Focus on clarity, simplicity and composability, resulting in a productive, fun, expressive and powerful language • No class inheritance. ‘Embedding’ & ‘Interfaces’ to provide polymorphism • Built-in parallelism & asynchrony via ‘Channels’ & ‘goroutines’ • Includes a - debugging, profiling, formatting and testing - toolset 4DEVNET-1808
  • 5. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Software engineering guided the design of Go https://talks.golang.org/2012/splash.article • Clear dependencies • Clear syntax • Clear semantics • Composition over inheritance • Simplicity provided by the programming model (garbage collection, concurrency) • Easy tooling (the go tool, gofmt, godoc, gofix) • TRY IT: https://tour.golang.org 5DEVNET-1808
  • 7. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 7DEVNET-1808 Variables https://tour.golang.org/basics
  • 8. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 8DEVNET-1808 Functions: mutiple results https://tour.golang.org/basics/6
  • 9. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 9DEVNET-1808 Functions: named results https://tour.golang.org/basics/7
  • 10. Setting up Go on your machine
  • 11. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Installing Go https://golang.org/doc/install • Download the PKG on Mac (or MSI forWindows), and Install • by default installs in /usr/local/go (or c:Go forWindows). • adds the Go binary to your PATH environment variable • Set the GOROOT env variable if you install to a different location • Type ‘go version’ to check your installation is successful • Create a ‘go’ workspace directory • under $HOME/go on Mac (or %USERPROFILE%go forWindows) • Set a GOPATH environment variable is preferable (and mandatory if elsewhere) • Add the $GOPATH/bin directory to your path 11DEVNET-1808
  • 12. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS HelloWorld (on a Mac) • Create a “src/hello” directory in your workspace • Create a file named hello.go • Build it with the go tool • Produces an executable named hello • Run go install to install the binary into your workspace's bin directory or go clean to remove it. 12DEVNET-1808 1 File: src/hello/hello.go 2 3
  • 13. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS HelloWorld (on Windows) • Create a “src/hello” directory in your workspace • Create a file named hello.go • Build it with the go tool • Produces an executable named hello.exe • Run go install to install the binary into your workspace's bin directory or go clean to remove it. 13DEVNET-1808 1 2 File: src/hello/hello.go 3
  • 14. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Typical go folder structure https://golang.org/doc/code.html • go tooling requires to organize your code in a specific way • Go programmers typically keep all their Go code in a single workspace. • A workspace contains many version control repositories (managed by git, for example). • Each repository contains one or more packages. • Each package consists of one or more Go source files in a single directory. • The path to a package's directory determines its import path. 14DEVNET-1808 GOPATH = C:Localgowork mkdir ‘$GOPATH/src/github.com/<username>/hello’
  • 15. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Creating a Library https://golang.org/doc/code.html > mkdir $GOPATH/src/github.com/<user>/hello 15DEVNET-1808 filename: hello.go
  • 16. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Creating a Library https://golang.org/doc/code.html > mkdir $GOPATH/src/github.com/<user>/stringutil 16DEVNET-1808 filename: reverse.go
  • 17. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Creating a Library https://golang.org/doc/code.html > go install github.com/<user>/hello • the ‘stringutil’ package is automatically installed as well • go executables are statically linked 17DEVNET-1808
  • 19. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Go Extension forVisual Studio Code 19DEVNET-1808 Installs automatically at launch or manually via go get –v: github.com/nsf/gocode github.com/uudashr/gopkgs/cmd/gopkgs github.com/ramya-rao-a/go-outline github.com/acroca/go-symbols golang.org/x/tools/cmd/guru golang.org/x/tools/cmd/gorename github.com/fatih/gomodifytags github.com/haya14busa/goplay/cmd/goplay github.com/josharian/impl github.com/rogpeppe/godef golang.org/x/tools/cmd/godoc sourcegraph.com/sqs/goreturns github.com/golang/lint/golint github.com/cweill/gotests github.com/derekparker/delve/cmd/dlv golang.org/x/tools/cmd/guru
  • 20. Demo
  • 21. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS VS Code golang extension: InstallationTips • If any go tools dependency is missing, install it manually • Make sure the $GOPATH/bin directory appears in your path • To install the Delve debugger, type > go get -u github.com/derekparker/delve/cmd/dlv • If having issue with the debugger on Mac: ‘lldb-server’ not found, type > xcode-select –install 21DEVNET-1808
  • 23. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Packaging for various platforms • The go toolchain natively cross-build executables for any Go-supported foreign platform • Example: > env GOOS=linuxGOARCH=amd64 go build -o dist/demo.linux -v main.go https://www.digitalocean.com/community/tutorials/how-to-build-go-executables- for-multiple-platforms-on-ubuntu-16-04 DEVNET-1808
  • 24. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS DEVNET-1808 Dockerfile example https://github.com/ObjectIsAdvantag/CLEUR-1814/tree/master/8-docker
  • 25. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 25DEVNET-1808 Pointers https://tour.golang.org/moretypes/1
  • 26. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 26DEVNET-1808 readword.go
  • 28. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Methods and Interfaces • Remember: a method is just a function with a receiver argument • To implement an interface inGo • Implement all the methods in the interface 28DEVNET-1808 https://tour.golang.org/methods https://gobyexample.com/interfaces https://github.com/ObjectIsAdvantag/CLEUR-1814/blob/master/7-spark/main.go https://github.com/ObjectIsAdvantag/CLEUR-1814/blob/master/6-interfaces/main.go
  • 30. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 30DEVNET-1808 Defer https://tour.golang.org/flowcontrol/12
  • 31. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Defer • defers the execution of a function until the surrounding function returns • deferred function calls are pushed onto a stack (executed in LIFO) 31DEVNET-1808 counting done 5 4 3 2 1 0
  • 32. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS HTTP API Clients • simplify development • speed up development • clean code • abstraction https://www.scaledrone.com/blog/posts/creating-an-api-client-in-go 32DEVNET-1808
  • 34. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 34DEVNET-1808 Concurrency: channels & go routines
  • 35. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 35DEVNET-1808 Structures https://tour.golang.org/moretypes/2
  • 36. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 36DEVNET-1808 Arrays https://tour.golang.org/moretypes/6
  • 37. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 37DEVNET-1808 Slices https://tour.golang.org/moretypes/13
  • 38. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 38DEVNET-1808 Maps https://tour.golang.org/moretypes/22
  • 39. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS 39DEVNET-1808 Closures https://tour.golang.org/moretypes/25
  • 41. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Wrapup… go for ITPros  CLI  Proxy  Reverse Proxy  Web API 41DEVNET-1808
  • 42. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS State of go – 2017 user survey • Continued growth in the language • Enterprise-ready: for the first time, more Go at work than home • Top-uses of Go is now writingAPI/RPC services • 2016 was stillCLI. Now taking advantage of the distinguishing features of Go, key elements of cloud computing • Biggest challenges: lack of dependency management, generics • 64% responses use Go on Linux, 49% on MacOS, 18% onWindows • VSCode is now the most popular editor for Go developers • Finding answers:Go website, Stack Overflow, and reading code • Primary news sources: Go blog, Reddit, andTwitter 42DEVNET-1808
  • 43. © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Cisco Community Contributions • golang samples • https://github.com/ObjectIsAdvantag/CLEUR-1814 • Cisco Spark REST API wrapper • https://github.com/jbogarin/go-cisco-spark • CiscoACI from golang • https://github.com/udhos/acigo • Answering Machine backed byTropo • https://github.com/ObjectIsAdvantag/answering-machine • Proxy incoming web hooks to established web sockets • https://github.com/sgrimee/whproxy 43DEVNET-1808
  • 44. Complete your online session evaluation © 2018 Cisco and/or its affiliates. All rights reserved. Cisco Public#CLUS Give us your feedback to be entered into a Daily Survey Drawing. Complete your session surveys through the Cisco Live mobile app or on www.CiscoLive.com/us. Don’t forget: Cisco Live sessions will be available for viewing on demand after the event at www.CiscoLive.com/Online. DEVNET-1808
  • 45. Q&A
  • 47. #CLUS

Editor's Notes

  • #4: Examples with what’s in the standard golang box Logs: https://github.com/sirupsen/logrus
  • #5: https://talks.golang.org/2012/splash.article
  • #13: Rather do ‘ $GOPATH/src/github.com/<username>/hello’
  • #14: Rather do ‘ $GOPATH/src/github.com/<username>/hello’
  • #25: https://cloud.google.com/appengine/docs/standard/go/tools/uploadinganapp
  • #26: Pass by value is not ineficient in many cases, or mandates to create placeholders / shared variables, or even understand the context of the stack in JS
  • #27: package main import (     "fmt" ) func readword() (word string) {     fmt.Println("Type something")     fmt.Scanf("%s", &word)     return } func main() {     w := readword()     fmt.Println("You entered", w) }
  • #31: Makes your code more elegant
  • #35: package main import ( "fmt" "time" ) func timeout(t chan bool) { time.Sleep(5 * time.Second) t <- true } func readword(ch chan string) { fmt.Println("Type something and hit Enter") var word string fmt.Scanf("%s", &word) ch <- word } func main() { t := make(chan bool) go timeout(t) ch := make(chan string) go readword(ch) select { case word := <-ch: fmt.Println("Received", word) case <-t: fmt.Println("Timeout.") } }
  • #40: For JS familiar developers