From a9886bf2f8a35369a2c42070c5f83504dfab2bc5 Mon Sep 17 00:00:00 2001 From: Jasper Ras Date: Fri, 27 Jun 2025 10:56:03 +0200 Subject: vault backup: 2025-06-27 10:56:02 --- Golang.md | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'Golang.md') diff --git a/Golang.md b/Golang.md index 3b3438f..ea9dfcd 100644 --- a/Golang.md +++ b/Golang.md @@ -1 +1,55 @@ -[[What are Type Assertions in Go and when to use them]] \ No newline at end of file +[[What are Type Assertions in Go and when to use them]] + +# TODO +make a note about : +statement -> expression -> declaration, etc. Idea: draw it in some way, making it visual might help remembering. +# DIGEST INTO NOTES +Slices are dynamically sized arrays that can be accessed `s[i]` or a subset can be taken `s[i:j]`. Indexing: half-open (starts at 0). `s[i:j]` yields i through j-1. Either can be omitted. + +Convention: comment describing package preceding package declaration. + +Variables initialised to "zero value".7689 +String concatenation via `+` char. +Supports assignment operators, e.g `+=`, `*=` etc +Short-hand variable declaration requires no type, it is inferred of the value `:=` **only allowed in a function** + +For-loop structure: +``` +for initialization; condition; post { + // code +} +``` +Either part can be left away with different semantics. +All parts gone: loop forever. +Only condition is like a while x == true; +`range` keyword to loop over a slice or array with `for index, arg := range slice` + +`_` is the blank identifier, thus above if we don' need the index we can put `_`. + +--- + +`image/color` package features the Color interface defining a Color as just a type that has a method `RGBA() (r, g, b, a uint32)`. It has a struct `RGBA` defining this method. So for example to define green we can say: `color.RGBA{0x00, 0xFF, 0x00, 0xFF}` R G B A respectively. + +Packaging doing stuff with networking are grouped under `net`, e.g `net/http` + +Using `io.Copy` we can copy output from a reader to a writer. This way we can for example copy a HTTP response directly to stdout instead of buffering the entire output first. + +`strings.HasPrefix` exists + +To get a time delta we can use `time.Since` which returns a `time.Time`. We can just call for example `Seconds()` on that to get the elapsed seconds. + +Goroutines run concurrently and communicate over channels, they are started with the `go` keyword. Sending or receiving on a channel block the goroutine. + +--- + +Order of map iteration is unspecified but random in practice to prevent reliance on ordering. +The Scanner type from the bufio package provides an easy way to read input in lines or words. +Map created with `make` is passed by reference. +Package `io/ioutil` exposes `ReadFile` and other io utility functions and types. +Casting works by `type(var)`, e.g `i := 0; string(i)` +Referencing a multi-component package is done through the last component. E.g `ioutil` for the `io/ioutil` package. +Composite literals are the form of `type{...}` they instantiate composite types, so `[]string{"a"}` is also a composite literal. + +--- + +Gin bool required bind fails if false, needs ptr to bool. https://github.com/gin-gonic/gin/issues/814 \ No newline at end of file -- cgit v1.2.3