From Ruby to Golang

From Ruby to Golang

Joel Bryan Juliano
This is a sample of the book's content.Buy on Leanpub

Table of Contents

From Ruby to Golang

  • Preface
  • Introduction
    • Who This Book Is For
    • How to Use This Book
    • What This Book Is Not
    • About the Author
  • Chapter 1: Getting Started
    • Package Name and Imports
    • Println
    • Printf
    • Sprintf
    • Putting It Together
    • Functions
    • Function Basics
    • Function Parameters and Arguments
    • Function Return Types
    • Main Function
    • Chapter Exercises
    • Summary
  • Chapter 5: Package Management
    • Sharing Go Packages
    • Go Modules
    • Manual go.mod Generation
    • Automatic go.mod Generation Through Source-Code
    • Refresh Go Modules
    • Go Workspaces
    • A Note on dep
    • Chapter Exercises
    • Summary
  • Chapter 2: Structs
    • Struct
    • Public Structs
    • Attaching a Struct to a Function
    • Pass-by-value and Pass-by-reference
    • Pointer Receiver
    • Value Receiver
    • Decouple and Reuse Structs through Embedding
    • Anonymous Structs
    • Anonymous Struct Fields
    • Summary
  • Chapter 3: Maps
    • Maps by Declaration
    • Initialization by Make
    • Initialization by Literal Type Assignment
    • Maps by Assignment
    • Assignment with a Key/Value
    • Assignment on an Empty Map
    • Using Struct in Maps
    • Struct Maps by Declaration
    • Struct Maps by Assignment
    • Struct Maps with Array Values
    • Maps with Dynamic Types
    • Deleting Map Values
    • Reading a Non-Present Key from a Map
    • Variadic Functions
    • Variadic Functions with Maps
    • Passing Variadic Arguments
    • Summary
  • Chapter 4: Arrays, Slices, and Iteration
    • Fixed Array
    • Fixed-Array Automatic Size Calculation
    • Fixed-Array Sizes
    • Fixed-Array Assignment Behaviour
    • Sliced Array
    • Sliced-Array Assignment Behaviour
    • Capacity
    • Deep Copy
    • Append
    • Arrays with Variadic Types
    • Mixed Array Types
    • Iterating Over Arrays
    • C-style Semantic Form
    • Value Semantic Form
    • Value Semantic Form with Muted Parameter
    • Index Semantic Form for Range
    • Value Semantic Form with Pointer Access
    • Summary
  • Chapter 6: Collection Functions
    • Predicate Method all?
    • Predicate Method any?
    • Collect Enumerable Method
    • Cycle Enumerable Method
    • Detect Enumerable Method
    • Drop Enumerable Method
    • Drop While Enumerable Method
    • Select and Reject
    • Reduce
    • Count
    • Min and Max
    • Sort
    • Group By
    • Summary
  • Chapter 7: Interfaces
    • Interface as a Self-Documenting API Reference
    • Interface as Type contract
    • Satisfying Return Values
    • Summary
  • Chapter 8: Error Handling
    • Ruby’s Exception Model
    • Go’s Error-as-Value Model
    • The error Interface
    • Creating Errors
    • Wrapping Errors
    • defer: Go’s ensure
    • panic and recover
    • When Rubyists Overuse Panic
    • Summary
  • Chapter 9: Concurrency
    • Goroutines
    • Channels
    • select — Multiplexing Channels
    • sync.WaitGroup — Waiting for Goroutines
    • sync.Mutex — When You Need a Lock
    • The Go Concurrency Proverb
    • Chapter Exercises
    • Summary
  • Chapter 10: Testing
    • Your First Go Test
    • Table-Driven Tests
    • Subtests and Helpers
    • Benchmarking
    • Chapter Exercises
    • Summary
  • Chapter 11: JSON & Struct Tags
    • Marshal: Struct to JSON
    • Struct Tags
    • Unmarshal: JSON to Struct
    • Nested Structs and Arrays
    • Custom JSON Marshaling
    • Chapter Exercises
    • Summary
  • Chapter 12: Generics
    • The Problem Generics Solve
    • Your First Generic Function
    • Constraints
    • The comparable Constraint
    • Generic Types
    • When to Use Generics
    • Generics vs Ruby Duck Typing
    • Chapter Exercises
    • Summary
  • Chapter 13: HTTP Servers
    • Your First HTTP Server
    • Request and Response
    • Reading a JSON Request Body
    • Status Codes and Headers
    • Middleware
    • A Complete REST Handler
    • Summary
  • Appendix A: Go ↔ Ruby Quick Reference
    • Syntax & Structure
    • Variables & Types
    • Data Structures
    • Functions & Methods
    • Error Handling
    • Concurrency
    • Packages & Modules
    • Common Patterns
    • Go CLI Cheat Sheet
    • File Layout
  • Appendix B: Exercise Answers
    • Chapter 1
    • Chapter 3
    • Chapter 4
    • Chapter 5
    • Chapter 8
    • Chapter 9
    • Chapter 10
    • Chapter 12
  • Glossary
  • Acknowledgments
  • Credits
From Ruby to Golang/Overview

From Ruby to Golang

Course overview

A practical guide that teaches Go by mapping every concept to Ruby. Structs, maps, goroutines, interfaces, and error handling — updated for Go 1.22+. For Rubyists who want to write production Go.

20 chapters
Begin reading
Download
The Book

From Ruby to Golang20 chapters

Begin ›
  1. Preface

  2. Introduction

  3. Chapter 1: Getting Started

  4. Chapter 5: Package Management

  5. Chapter 2: Structs

  6. Chapter 3: Maps

  7. Chapter 4: Arrays, Slices, and Iteration

  8. Chapter 6: Collection Functions

  9. Chapter 7: Interfaces

  10. Chapter 8: Error Handling

  11. Chapter 9: Concurrency

  12. Chapter 10: Testing

  13. Chapter 11: JSON & Struct Tags

  14. Chapter 12: Generics

  15. Chapter 13: HTTP Servers

  16. Appendix A: Go ↔ Ruby Quick Reference

  17. Appendix B: Exercise Answers

  18. Glossary

  19. Acknowledgments

  20. Credits