Rubyer learning Go

It’s time to study a compile language! Go

No class but package

Handle error everywhere

Go package Reflect


*string means ? allow this field to be nil

import . “” // what does “_” means ? means only invoke init() of the package but not include it

Array… means ? open and assign array elements. like in ruby: a,b,c = [1,2,3]

value.(Injector) Injector is an interface, this expression means if value implemented Injector’s functions

type Context struct {

Mixin Searcher into Context. You can call is defined in Searcher) directly

Pointer study

func *(string) memoryLocation and func &(string) pointer


type Shape interface {

type Circle struct {

func (c *Circle) area() {
  fmt.Println("I'm a circle")

type Rectangle struct {

func (c *Rectangle) area() {
  fmt.Println("I'm a rectangle")

In this example, Circle and Rectangle can be used as “Shape” together. like this

func totalArea(shapes ...Shape) {
  for _, s := range shapes {

totalArea(&c, &r)

Kind of duck typing in Go…