随笔分类 -  Golang

摘要:参考文档:https://github.com/qax-os/excelize 安装 excelize包 go get github.com/xuri/excelize/v2 创建电子表格 func TestCreateSpreadsheet(t *testing.T) { f := exceliz 阅读全文
posted @ 2022-03-15 23:07 GetcharZp 阅读(1030) 评论(0) 推荐(0) 编辑
摘要:首先准备一个简单的图片 qrcode.png 了解下几个处理图片的方法 image.Decode() // 得到文件的图片对象 image.NewRGBA() // 创建一个真彩色的图像对象 *RGBA func (p *RGBA) Bounds() Rectangle { return p.Rec 阅读全文
posted @ 2022-03-13 16:26 GetcharZp 阅读(1090) 评论(0) 推荐(0) 编辑
摘要:方法一:使用 sort.Slice() 进行排序 package main import ( "fmt" "sort" ) type myStruct struct { name string score int } func main() { s1 := []myStruct{ {name: "m 阅读全文
posted @ 2022-02-10 12:47 GetcharZp 阅读(1296) 评论(0) 推荐(0) 编辑
摘要:参考文档:https://www.grpc.io/docs/languages/go/quickstart/ 环境配置 一、安装protobuf编译器 在 https://github.com/protocolbuffers/protobuf/releases 这个网址中根据自己的操作系统下载对应的 阅读全文
posted @ 2022-02-09 22:32 GetcharZp 阅读(140) 评论(0) 推荐(0) 编辑
摘要:参考地址:https://github.com/go-redis/redis 定义上下文以及连接的相关信息 var ctx = context.Background() var rdb = redis.NewClient(&redis.Options{ Addr: "localhost:6379", 阅读全文
posted @ 2022-01-24 14:23 GetcharZp 阅读(427) 评论(0) 推荐(0) 编辑
摘要:Rabbit 默认的端口5672 默认启动方式如下(可登录容器后使用简单的命令进行管理) docker run -d --hostname my-rabbit --name some-rabbit rabbitmq:3 rabbit cli 工具 rabbitmqctl for service ma 阅读全文
posted @ 2021-12-14 14:05 GetcharZp 阅读(567) 评论(0) 推荐(0) 编辑
摘要:golang 中本身不支持三目运算,如果想要简化代码,可以自定义一个三目运算的函数,通过函数的调用来实现三目运算 package main import ( "fmt" ) // 三目运算的函数 func ternary(a bool, b, c interface{}) interface{} { 阅读全文
posted @ 2021-08-22 16:17 GetcharZp 阅读(2524) 评论(0) 推荐(0) 编辑
摘要:package main import ( "fmt" "errors" ) type Stack []int // 入栈 func (s *Stack) push(a int) { *s = append(*s, a) } // 出栈 func (s *Stack) pop() (int, err 阅读全文
posted @ 2021-08-22 00:29 GetcharZp 阅读(199) 评论(0) 推荐(0) 编辑
摘要:用法一: 为函数设置不定长度的参数 func myPrint(x ...interface{}) { for _, v := range x { fmt.Println(v) } } 用法二: 为数组设置默认长度 a := [...]int{12, 32, 12} // [12 32 12] 3 3 阅读全文
posted @ 2021-08-17 14:56 GetcharZp 阅读(94) 评论(0) 推荐(0) 编辑
摘要:1、新建 conf.yaml 文件 database: dbtype: mysql dbname: database table: table username: username password: password application: port: 8000 2、新建 conf.go 文件 阅读全文
posted @ 2021-01-06 16:12 GetcharZp 阅读(1373) 评论(0) 推荐(0) 编辑
摘要:leetcode 1. 两数之和 (Golang) func twoSum(nums []int, target int) []int { flag := make([]int, len(nums)) ans := make([]int, 0) for i, v := range nums { fo 阅读全文
posted @ 2020-10-18 23:02 GetcharZp 阅读(159) 评论(0) 推荐(0) 编辑
摘要:通过 fmt.Scanln() 来获取同一行的数据,使用空格来分别不同的数据 参考案例: package main import ( "fmt" ) func main() { var a, b int fmt.Scanln(&a, &b) fmt.Print(a, b, a + b) } 阅读全文
posted @ 2020-10-18 15:18 GetcharZp 阅读(276) 评论(0) 推荐(0) 编辑

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