随笔分类 - software engineering / Golang
摘要:Before we embark on our journey through the world of pointers in Go, we must fist grasp the significance of the & operator. func main() { var i int =
阅读全文
摘要:Known for its speed and small memory footprint, Gin is one of the most popular and widely used Go web frameworks. It provides features like routing, m
阅读全文
摘要:首先往数据库插入数据,就需要连接数据库(笔者此处使用的是PostgreSQL) 因此在项目中引入如下依赖(这两个依赖版本号不一致,可能会出现异常) gorm.io/driver/postgres // 依赖是用于连接和操作 PostgreSQL 数据库 gorm.io/gorm // 对象关系映射
阅读全文
摘要:前提:搭建好Golang环境 首先新建project,Goland会自动生成go.mod文件。 GOPROXY=https://proxy.golang.com.cn,direct // 设置官方镜像代理,阿里镜像代理实测过程中遇到了一些问题 下载并安装Gin框架,并将其添加到你的项目的Go模块中(
阅读全文
摘要:闭包是指一个函数值(function value),它可以引用其函数体之外的变量 闭包代码示例 func makeSuffix() func(str string) string { var suffix = ".jpg" return func(str string) string { if st
阅读全文
摘要:递归函数的两个特征 函数自己调用自己 一定存在某个条件来终止递归,以避免无限递归 func main() { // result is : 2 2 3 recursion(4) } func recursion(num int) { if num > 2 { num-- recursion(num)
阅读全文
摘要:* * * * * * * * * * * * * * * * * * * * * * * * 需求:在控制台打印如上图所示的效果图 解题思路: 首先简化问题,用嵌套for循环打印出实心金字塔,由题可观察得知,层数与star(星号)数量保持着一定关系(奇数队列),1、3、5、7……2n-1 然后,格
阅读全文