随笔分类 -  Go

摘要:Here is how typescript does the same thing export type Data = { projector: { //pwd [key: string]: { // key -> value [key: string]: string, } } } Here 阅读全文
posted @ 2024-02-29 19:54 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要:Code: config.go package projector import ( "fmt" "os" "path" ) type Operation = int const ( Print Operation = iota Add Remove ) type Config struct { A 阅读全文
posted @ 2024-02-26 15:47 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:// interface {} is the same as `any` type in Typscript func add(inputs []int) interface {} { return inputs[0].Float() + inputs[1].Float() } 阅读全文
posted @ 2024-02-19 20:58 Zhentiw 阅读(2) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "log" "strconv" "strings" ) type Point struct { x int y int } type Line struct { p1 *Point p2 *Point } func getInput() str 阅读全文
posted @ 2024-02-19 15:58 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-18 04:05 Zhentiw 阅读(15) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-18 03:58 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-09 15:58 Zhentiw 阅读(7) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-06 22:16 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要:So, let's say we have a function to fetch crypto currencies price: package main import ( "fmt" "sync" "project/api" ) func main() { go getCurrencyData 阅读全文
posted @ 2024-02-06 22:03 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-06 16:16 Zhentiw 阅读(1) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2024-02-06 03:40 Zhentiw 阅读(11) 评论(0) 推荐(0) 编辑
摘要:Panic recovery is a mechanism in Go that allows a program to handle unexpected errors (panics) gracefully. package main import ( "fmt" ) func mayPanic 阅读全文
posted @ 2024-02-06 03:24 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:defermake sure the operation will be executed at the end of a function. func loadChampions() ([]champion, error) { file, err := os.Open("tft_champions 阅读全文
posted @ 2024-02-06 03:22 Zhentiw 阅读(3) 评论(0) 推荐(0) 编辑
摘要:package data // new type type distance float64 type distanceKm float64 // add ToKm method to distance type func (miles distance) ToKm() distanceKm { / 阅读全文
posted @ 2023-11-21 15:49 Zhentiw 阅读(8) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2023-11-16 15:28 Zhentiw 阅读(5) 评论(0) 推荐(0) 编辑
摘要:package main import ( "bufio" "fmt" "os" "strings" ) type name struct { fname []byte lname []byte } func main() { fmt.Print("File path ") var filename 阅读全文
posted @ 2022-09-13 20:39 Zhentiw 阅读(12) 评论(0) 推荐(0) 编辑
摘要:ary := [...]int {1,2,3,4} // array sli := []int {1,2,3,4}// slice 阅读全文
posted @ 2022-09-12 00:05 Zhentiw 阅读(4) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-09-08 18:07 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2022-09-08 15:08 Zhentiw 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Stack is dedicated to function Local variables are store in stack Deallocated after function completes Heap is persisten Carbage Collections Go is a c 阅读全文
posted @ 2022-09-07 16:17 Zhentiw 阅读(10) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示