摘要:
Implement the built-in ReturnType<T> generic without using it. For example const fn = (v: boolean) => { if (v) return 1 else return 2 } type a = MyRet 阅读全文
摘要:
// User type User struct { ID int FirstName string } // Method func (u *User) describe() string { desc := fmt.Sprintf("Name %s", u.FirstName) return d 阅读全文
摘要:
package main import ( "fmt" ) func recoverFromPanic() { fmt.Println("defer") } func doThings() { defer recoverFromPanic() for i := 0; i < 5; i++ { fmt 阅读全文
摘要:
package main import ( "errors" "fmt" "strings" ) func shouldGreaterThanTen(num int) error { if num < 10 { return errors.New("Number is less than 10") 阅读全文
摘要:
func changeName(name *string) { *name = strings.ToUpper(*name) } // Coordinates type Coordinates struct { X, Y float64 } func main() { name := "Elvis" 阅读全文
摘要:
var name string var namePointer *string // Pointer name = "Beyonce" namePointer = &name // Assign a Pointer fmt.Println("Name: ", name) fmt.Println("N 阅读全文