meowrain

MeowRain

Life is Simple

Go实现递归向下分析

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 package main import ( "bufio" "fmt" "os" "strings" ) var ( str []byte pointer int error_str string = "Error: 非法的符号串" withNoSharp string = "Error: 符号串必须以#结尾" ) // 打印颜色设置 const Red = "\033[31m" const Green = "\033[32m" const Reset = "\033[0m" const Yellow = "\033[33m" func match(token byte) { if pointer >= len(str) { errors(error_str) return } if str[pointer] == token { pointer++ } else { errors(error_str) } } func errors(info string) { fmt.

Go数组和切片联系

Go数组和切片练习 数组 练习1:证明当数组赋值时,发生了数组内存拷贝。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 package main import "fmt" func main() { arr1 := new([5]int) arr2 := arr1 arr2[1] = 3 fmt.Println(arr1) //&[0 3 0 0 0] fmt.Println(arr2) //&[0 3 0 0 0] arr3 := [5]int{1, 2, 3, 4, 5} arr4 := &arr3 //使用&获取地址,修改arr4也会修改arr3 arr4[2] = 6 fmt.Println(arr3) //[1 2 6 4 5] fmt.

Go接口

Go 接口 接口定义 Go语言提倡面向接口编程。 指针接收者实现接口 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 package main import "fmt" // 接口定义 type USB interface { Connect() Disconnect() } type Laptop struct { name string version string } type Desktop struct { name string version string } // 实现USB接口 func (laptop *Laptop) Connect() { fmt.

Go文件读写

参考文档:https://www.liwenzhou.com/posts/Go/file/ 读取文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 package main import ( "fmt" "io" "os") func main() { file, err := os.Open("./data.txt") if err != nil { fmt.Println("open file err:", err) return } defer file.Close() var tmp = make([]byte, 1024) n, err := file.Read(tmp) if err == io.EOF { fmt.Println("文件读取完毕") return } fmt.Printf("读取了%d字节数据\n", n) fmt.

Go语言 Web框架Gin

Go 语言 Web 框架 Gin 参考 https://docs.fengfengzhidao.com https://www.liwenzhou.com/posts/Go/gin/#c-0-7-2 返回各种值 返回字符串 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 package main import ( "net/http" "github.com/gin-gonic/gin" ) func main() { router := gin.Default() router.GET("/", func(c *gin.Context) { c.String(http.StatusOK, "helloworld") }) router.Run(":8080") } 返回 json 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 package main import ( "net/http" "github.
0%