Skip to content

Slide, code samples, and resources for "A Tour of Go for the C# Developer" (uses Go 1.18 and C# 6.0)

License

Notifications You must be signed in to change notification settings

jeremybytes/go-for-csharp-dev-2022

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go for the C# Developer 2022 (Go 1.18)

This repository contains slides and code samples for the presentation "A Tour of Go for the C# Developer". This is the 2022 version of the presentation and covers Go 1.18 (released March 2022).

Motivation

Learning other programming languages enhances our work in our primary language. From the perspective of a C# developer, the Go language (golang) has many interesting ideas. Go is opinionated on some things (such as where curly braces go and what items are capitalized). Declaring an unused variable causes a compile failure; the use of "blank identifiers" (or "discards" in C#) are common. Concurrency is baked right in to the language through goroutines and channels. Programming by exception is discouraged; it's actually called a "panic" in Go. Instead, errors are treated as states to be handled like any other data state. We'll explore these features (and others) by building an application that uses concurrent operations to get data from a service. These ideas make us think about the way we program and how we can improve our day-to-day work (in C# or elsewhere).

Video Walkthrough: If you prefer a video walkthrough of the code, take a look at this video on YouTube: A Tour of Go (golang) for the C# Developer.

Pre-requisites

If you want to build and run the code, you will need to have both Go 1.18 and .NET 6.0 installed on your machine.

This project assumes that you have both "go" (this was created with version 1.18) and "dotnet" (this was created with 6.0.201) installed.

Samples should work on all platforms supported by the runtimes (Windows, macOS, and Linux).

Project Layout

/tour-of-go contains the Go program
/net-people-service contains a .NET 6 service (used by the Go program)

The Go program is a console application that calls the .NET service and displays the output. In order to show concurrency, the application gets each record individually.

Running the Service

The .NET service can be started from the command line by navigating to the ".../net-people-service" directory and typing dotnet run. This provides endpoints at the following locations:

  • http://localhost:9874/people/1
    Provides an individual "Person" record based on the "id" value. This service will delay for 1 second before responding. Sample record:
{"id":1,"givenName":"John","familyName":"Koenig","startDate":"1975-10-17T00:00:00-07:00","rating":6,"formatString":null}

The Go Sample Program

The /tour-of-go folder contains the "main.go" file which is the completed project.

Note: If you would like a step-by-step walkthrough of a similar project, check out the video walkthrough (A Tour of Go (golang) for the C# Developer) and the accompanying GitHub repo (https://github.com/jeremybytes/video-go-for-csharp-dev)

Other Topics

This is by no means an exhaustive look at Go. Additional topics and topics to look into further include packages, exports, project structure, types, interfaces, and pointers.

Here are a few articles (written by me):

Other Resources:

About

Slide, code samples, and resources for "A Tour of Go for the C# Developer" (uses Go 1.18 and C# 6.0)

Topics

Resources

License

Stars

Watchers

Forks