💻
Software Engineering Notes
  • Introduction
  • Event-Sourcing
  • CQS and CQRS
  • Domain-Driven Design
    • Overview
    • Business Domain
    • Subdomain
    • Bounded Context
      • Interaction Between Contexts
    • Layers
      • Domain Layer
      • Application Layer
      • Infrastructure Layer
  • Database
    • In-Memory (Redis)
    • Search Engine (Elasticsearch)
    • Column-Oriented (Cassandra)
    • Document-Oriented (MongoDB)
  • Messaging
    • Brokers
      • Kafka
  • Race Condition
  • Concurrency vs Parallelism
  • API Architectural Styles
    • gRPC
  • Language & Framework Specific Notes
    • Go (Golang)
Powered by GitBook
On this page
  • Getting Started
  • Important Stuff to Note
  • Closure
  • Struct Embedding
  1. Language & Framework Specific Notes

Go (Golang)

PreviousLanguage & Framework Specific Notes

Last updated 1 year ago

Getting Started

Important Stuff to Note

  • Go does not have classes.

  • In general, all methods on a given type should have either value or pointer receivers, but not a mixture of both.

  • Goroutine is more or less similar to Java's process fork. The goroutine will also be stopped if the main process is stopped.

    • Communications can be done between goroutines with channel.

Method with Pointer Receiver

A method with pointer receiver behaves differently:

func (v *Vertex) Scale(f float64) {
    ...
}

The vertex's value will change on the struct. This is similar to having func Scale(v *Vertex, f float64) which will use the same Vertex instead of copying the Vertex.

Closure

It might not be a good idea to use closures a lot, this is because closures do have a side-effect.

It is still okay to use it sparingly, one of the use-case where I might use it is for memoization:

Struct Embedding

If a struct's field do not have a name, it is a struct embedding.

A type implements an interface by implementing its methods. There is no explicit declaration of intent, no "implements" keyword.

https://go.dev/tour/methods/10
A Tour of Go
Go by Example
Logo
Add a cache to a go function as if it were a static memberStack Overflow
Go by Example: Struct Embedding
Logo
Logo
Logo