![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Golang
Uoyaij_
这个作者很懒,什么都没留下…
展开
-
Golang template.ParseFiles路径问题
今天学到Goweb时测试模板引擎的使用发现一个问题,代码如下:结构:package mainimport ( "fmt" "html/template" "net/http")func testTemplate(w http.ResponseWriter, r *http.Request) { //解析模板 t, err := template.ParseFiles("hello.html") //执行 fmt.Println("error=", err) t.Execut原创 2021-08-03 00:05:39 · 1546 阅读 · 1 评论 -
VScode解决Go插件安装失败问题
按ctrl+shift+p找到所需要安装的Go插件方式一:方式二:如果直接安装,控制台会有很多Failed出现,这时候我们只需在环境变量中设置GOPROXY=https://goproxy.io,direct(Linux环境也是一样)再回到VScode安装即可可以看到安装成功!...原创 2021-07-28 17:38:44 · 553 阅读 · 0 评论 -
Golang、redis连接池的使用
package mainimport ( "fmt" "github.com/gomodule/redigo/redis" //引入redis)//定义全局pool(连接池)var pool *redis.Pool//当启动程序时,就初始化连接池func init() { pool = &redis.Pool { MaxIdle: 8 ,//最大空闲链接数 MaxActive: 0, //表示和数据库的最大链接数,0表示没有限制 IdleTimeout: 10原创 2021-07-20 11:20:50 · 175 阅读 · 0 评论 -
Golang连接Redis基本操作
下载redis下载相关redis包启用命令:go get github.com/gomodule/redigo/redis获取到:引入:案例案例一通过go,向redis写入数据string[key-val]package mainimport ( "fmt" "github.com/gomodule/redigo/redis" //引入redis)func main() { //通过go向redis写入数据和读取数据 //1.连接到redis conn,原创 2021-07-19 18:47:59 · 714 阅读 · 0 评论 -
go语言多线程(goroutine)和管道(channel)
1、一个线程往管道里写数据、另一个线程从管道里读数据示例package mainimport ( "fmt")//writerDatafunc writerData(intChan chan int) { for i := 1; i <= 50; i++ { //放入数据 intChan<- i fmt.Printf("writeData 写到数据=%v\n", i) } close(intChan) //关闭}//readDatafunc read.原创 2021-07-17 10:59:59 · 1879 阅读 · 0 评论 -
GO语言学习:记录今日fmt.Scanf踩坑
分别执行这三个程序时,控制台中会得到不同的结果控制台的结果没贴出来,在查阅到官方文档:文档中提到Scanf函数会接收到一个参数以及一个error,当我们使用fmt.Scanf(" %d", num)实际上接收到的num值其实是0,这也是才坑点之一。所以在正确用法上得知尤其是在使用循环时最好还是使用fmt.Scanf("%d ", num)写法。...原创 2021-07-03 01:19:13 · 847 阅读 · 0 评论