随笔分类 - Go
摘要:Here is how typescript does the same thing export type Data = { projector: { //pwd [key: string]: { // key -> value [key: string]: string, } } } Here
阅读全文
摘要:Code: config.go package projector import ( "fmt" "os" "path" ) type Operation = int const ( Print Operation = iota Add Remove ) type Config struct { A
阅读全文
摘要:// interface {} is the same as `any` type in Typscript func add(inputs []int) interface {} { return inputs[0].Float() + inputs[1].Float() }
阅读全文
摘要:package main import ( "fmt" "log" "strconv" "strings" ) type Point struct { x int y int } type Line struct { p1 *Point p2 *Point } func getInput() str
阅读全文
摘要:Golang has no built-in function(s) to filter an array. This lesson will teach you two different ways to filter. The first is to create a separate arra
阅读全文
摘要:There are numerous ways that you can declare and create arrays and slices in Go. This lesson will show you several and I talk about the advantages and
阅读全文
摘要:Hello World Let's create a simple Go server, first let's setup the server and do hello world // @filename: main.go package main import ( "fmt" "net/ht
阅读全文
摘要:Vanilla Go includes Testing A test is a file with suffix_test.go You define functions with prefix Test and with an special signature receiving a *test
阅读全文
摘要:So, let's say we have a function to fetch crypto currencies price: package main import ( "fmt" "sync" "project/api" ) func main() { go getCurrencyData
阅读全文
摘要:A goroutine is the Go way of suing threads, we open a goroutine just by invoking any function with a go prefix. go functionCall() Goroutines can commu
阅读全文
摘要:Go has a special indexing syntax that forms the basis of removing one or more elements from a slice. I will teach you this syntax and show you its var
阅读全文
摘要:Panic recovery is a mechanism in Go that allows a program to handle unexpected errors (panics) gracefully. package main import ( "fmt" ) func mayPanic
阅读全文
摘要:defermake sure the operation will be executed at the end of a function. func loadChampions() ([]champion, error) { file, err := os.Open("tft_champions
阅读全文
摘要:package data // new type type distance float64 type distanceKm float64 // add ToKm method to distance type func (miles distance) ToKm() distanceKm { /
阅读全文
摘要:In Go, function can return multi value: func addAndSubstract(a int, b int) (int, int) { return a+b, a-b } It is also possible to define named return v
阅读全文
摘要:package main import ( "bufio" "fmt" "os" "strings" ) type name struct { fname []byte lname []byte } func main() { fmt.Print("File path ") var filename
阅读全文
摘要:ary := [...]int {1,2,3,4} // array sli := []int {1,2,3,4}// slice
阅读全文
摘要:Scan reads user input Takes a pointer as an argument Typed data is written to pointer Return number of scanned items var appleNum int fmt.Printf("Numb
阅读全文
摘要:iota Generate a set of related but distinct constants Often represents a property which has several distinct possible values Dyas of the week Months o
阅读全文
摘要:Stack is dedicated to function Local variables are store in stack Deallocated after function completes Heap is persisten Carbage Collections Go is a c
阅读全文