
Go技术积累
文章平均质量分 67
chen_peng7
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【GO】 33.go-zero 示例
go-zero 示例原创 2023-08-07 13:40:18 · 944 阅读 · 0 评论 -
【GO】31.grpc 客户端负载均衡源码分析
grpc client balancer原创 2023-02-27 21:33:04 · 748 阅读 · 0 评论 -
【GO】30.grpc拦截器源码分析
grpc拦截器源码分析原创 2023-02-27 17:37:41 · 743 阅读 · 0 评论 -
【GO】29.go-gin支持ssl/tls,即https示例
通过自制证书支持本地环境https服务正常运行,实现gin框架https双向认证。原创 2023-02-11 11:39:45 · 5239 阅读 · 2 评论 -
【GO】28.golang http包源码
Go 语言标准库 net/http 包提供了非常易用的接口,如下所示,我们可以利用标准库提供的功能快速搭建新的 HTTP 服务:func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])}func main() { http.HandleFunc("/", handler) log.Fatal(http.Liste原创 2021-07-14 17:37:59 · 287 阅读 · 0 评论 -
【GO】27. zookeeper golang库go-zookeeper实例
Golang 操作 zookeeper使用库:https://github.com/samuel/go-zookeeper文档地址:http://godoc.org/github.com/samuel/go-zookeeper/zk连接zk serverpackage mainimport ( "fmt" "github.com/samuel/go-zookeeper/zk" "time")func main() { // 创建zk连接地址 hosts := [].原创 2020-10-19 16:14:46 · 1613 阅读 · 1 评论 -
【GO】26. golang iris prometheus grafana 监控
1.引入包go get github.com/prometheus/client_golang2.添加metrics路径app.Get("/metrics", http.UnGzip, iris.FromStd(promhttp.Handler()))func UnGzip(ctx context.Context) { ctx.Gzip(false) ctx.Next()}3.启动项目查看默认数据4.Grafana添加模版...原创 2020-09-23 19:51:42 · 785 阅读 · 0 评论 -
【GO】25. golang flag小示例
运行程序时通过命令传递参数代码示例:package mainimport ( "flag" "fmt")var ( flagC = flag.String("c", "config.toml", "config file path") flagN = flag.Int("n", 1, "number"))func main() { flag.Parse()...原创 2020-05-06 20:21:02 · 244 阅读 · 0 评论 -
【GO】18.golang toml配置文件实例
获取包 go get github.com/BurntSushi/toml 添加.toml文件 [env]debug = truehost = "127.0.0.1"port = 1080ips = ["127.0.0.1", "127.0.0.2", "127.0.0.3"]ids = [1,...原创 2019-06-27 14:28:15 · 1230 阅读 · 0 评论 -
【GO】22.go 测试库 convey
下载convey库: go get github.com/smartystreets/goconvey 测试函数 some_functions.gopackage goconveydemoimport "errors"func IsEqual(a, b int) bool{ return a == b}func IsEqualWithErr(a, b ...原创 2019-07-08 16:10:55 · 1204 阅读 · 0 评论 -
【GO】23.Golang 测试库 testify
下载testify库 go get github.com/stretchr/testify 测试方法 package goconveydemoimport "errors"func IsEqual(a, b int) bool{ return a == b}func IsEqualWithErr(a, b int) (bool, error){ if a &...原创 2019-07-08 17:03:44 · 1608 阅读 · 0 评论 -
【GO】21.goquery html页面分析golang库
下载包: go get github.com/PuerkitoBio/goquery 示例代码: package mainimport ( "fmt" "log" "net/http" "github.com/PuerkitoBio/goquery")func ExampleScrape() { // Request the HTML pa...原创 2019-07-03 20:49:11 · 767 阅读 · 0 评论 -
【GO】24.golang 日志库 zap
下载库 go get go.uber.org/zap 快速开始代码 package mainimport ( "go.uber.org/zap" "time")func main() { url := "http://www.google.com" //print format log loggerDev, _ := zap.NewDevelopme...原创 2019-07-09 16:59:06 · 961 阅读 · 0 评论 -
【GO】19.封装一个简单的ticker
go的time.Timer.stop()以及time.Ticker.stop()在关闭时不会关闭它自己的channel因此在循环调用这两个结构的channel时要注意,避免内存泄漏。 封装Ticker package tickerimport ( "fmt" "time")type Ticker struct { Interval time.Durati...原创 2019-06-28 16:53:49 · 288 阅读 · 0 评论 -
【GO】20.golang http请求实例
通用方法 package httpimport ( "bytes" "gosports/common/consts" "io/ioutil" "net/http")func Get(url string) ([]byte, error) { resp, err := http.Get(url) if err != nil{ return nil, err }...原创 2019-06-29 16:46:54 · 424 阅读 · 0 评论 -
【GO】17.Golang IDE下使用Go Module
创建新项目并用Golang IDE打开 mac下 Golang -> Perferences -> Go -> Go Modules(vgo) -> Enable Go Modules (vgo) integration打勾结构及代码:gosports/src/common/entity/test.gopackage entitytype ...原创 2019-06-25 14:40:04 · 3985 阅读 · 0 评论 -
【转】【GO】16.Go module包管理
go module 介绍:自Go1.1.1版本发布(2018-08-24发布),从官方的博客中看到,其中有个比较突出的特色就是module,模块概念。module是一个相关Go包的集合,它是源代码更替和版本控制的单元。模块由源文件形成的go.mod文件的根目录定义,包含go.mod文件的目录也被称为模块根。moudles取代旧的的基于GOPATH方法来指定在工程中使用哪些源文件或导入包。模块...转载 2019-06-25 11:34:47 · 889 阅读 · 0 评论 -
【GO】 1.Go的参数传递都是值传递
在 Golang 中函数之间传递变量时总是以值的方式传递的,无论是 int,string,bool,array 这样的内置类型(或者说原始的类型),还是 slice,channel,map 这样的引用类型,在函数间传递变量时,都是以值的方式传递,也就是说传递的都是值的副本。 1.int类型值传递的代码示例: package mainimport ( "fmt")func m...原创 2019-04-12 17:48:43 · 1404 阅读 · 0 评论 -
【GO】3.Golang Http服务 get和post请求代码示例
一.服务器端编写两个接口:PostUser,GetUser package mainimport ( "encoding/json" "fmt" "io/ioutil" "net/http" "time")type User struct { Name string `json:"Name"` Age int `js...原创 2019-04-17 19:57:12 · 1332 阅读 · 0 评论 -
【GO】5.无缓冲通道与缓冲通道为1的区别 #channel#
无缓冲通道channel必须在接受方与发送方同时准备好时,通道才能正常传递数据,否则双方只有一方在线都会阻塞。缓冲通道当缓冲区满时,发送数据会阻塞,当缓冲区空时,接受数据会阻塞。发送方与接收方不需要同时做好准备。看一下以下代码:1.无缓冲通道如果将接收方与发送方放在一个程序里,会死锁。package mainimport ( "fmt")func main() { ...原创 2019-05-01 17:29:46 · 2767 阅读 · 0 评论 -
【GO】6.锁
1.互斥锁:sync.Mutex 当多个线程同时修改一个公共资源时,需要进行同步控制import "sync"var { mu sync.Mutex balance int}func Deposit(amount int){ mu.lock() defer mu.Unlock() balance = balance + amount...原创 2019-05-01 18:27:18 · 335 阅读 · 0 评论 -
【GO】7. redis go语言实例
1.redis安装见本人博文 https://blog.csdn.net/chen_peng7/article/details/70228609 2.使用开源库redigo操作redis github地址:https://github.com/garyburd/redigo文档地址:http://godoc.org/github.com/garyburd/redigo/red...原创 2019-05-02 17:48:42 · 331 阅读 · 0 评论 -
【GO】 4.Golang gin Web框架的一个示例
1.安装github.com/gin-gonic/gin 输入命令go get github.com/gin-gonic/gin 进行安装当长时间没有反应的时候我就知道又有一些包被墙了,这次还是两个。然而一点也不慌,还是手动去github上下载缺失的包之后运行:install $(GOPATH)\src\github.com/gin-gonic/gin 手动安装 2.一...原创 2019-04-18 19:35:03 · 1901 阅读 · 0 评论 -
【GO】8.grpc示例
1.安装protoc 地址https://github.com/protocolbuffers/protobuf/releases下载安装文件,windows为例下载下载后解压缩在bin目录下有protoc.exe打开cmd将目录定位为/protoc/bin下输入命令protoc --version如下图,说明安装成功 2.安装插件protoc-gen-go ...原创 2019-05-04 01:21:50 · 628 阅读 · 1 评论 -
【转】【GO】9.go:linkname
go:linkname的官方说明//go:linkname localname importpath.nameThe //go:linkname directive instructs the compiler to use “importpath.name” as the object file symbol name for the variable or function decl...转载 2019-05-25 20:28:28 · 501 阅读 · 0 评论 -
【GO】11.elasticsearch Golang olivere/elastic
Golang 操作 elasticsearch 第三方库 github.com/olivere/elastic 添加实体类 自己测试实体类可以简单一点,工作中的实体实例直接拿过来用了,实体对象有点复杂package entitiesimport "fmt"type Result struct { Geometry Geometry `...原创 2019-05-30 17:37:12 · 3323 阅读 · 0 评论 -
【GO】12.Iris Web框架实例
Iris号称最快的go语言Web框架 安装iris go get -u github.com/kataras/iris 官方的一个简单的web实例 package mainimport "github.com/kataras/iris"func main(){ app := iris.Default() app.Get("/ping", func(ct...原创 2019-05-31 11:53:54 · 2796 阅读 · 0 评论 -
【GO】14.sarama lib实现kafka实例
Mac安装kafka Homebrew安装brew install kafka安装会依赖zookeeper。 注意:安装目录:/usr/local/Cellar/kafka/2.2.1安装的配置文件路径/usr/local/etc/kafka/server.properties/usr/local/etc/kafka/zookeeper.properties启动z...原创 2019-06-05 20:04:06 · 1302 阅读 · 1 评论 -
【GO】13.Iris WebSocket 实例
iris websocket服务端 package mainimport ( "fmt" "github.com/kataras/iris" "github.com/kataras/iris/websocket")func main() { app := iris.New() app.Get("/", func(ctx iris.Context) { ctx....原创 2019-05-31 16:40:22 · 5165 阅读 · 1 评论 -
【GO】15.beanstalkd实例
beanstalkd 简介 Beanstalkd,一个高性能、轻量级的分布式内存队列系统,最初设计的目的是想通过后台异步执行耗时的任务来降低高容量Web应用系统的页面访问延迟,支持过有9.5 million用户的Facebook Causes应用。后来开源,现在有PostRank大规模部署和使用,每天处理百万级任务。Beanstalkd是典型的类Memcached设计,协议和使用方式都是同...原创 2019-06-06 14:16:05 · 506 阅读 · 0 评论 -
【GO】 2.使用github.com/denisenkom/go-mssqldb操作数据库
一.下载安装github.com/denisenkom/go-mssqldb包 安装需要输入命令:go get github.com/denisenkom/go-mssqldb正常情况下输入以上命令就已将包下载并安装完毕然而这个包有一个依赖包cloud.google.com/go/civil,看到google有没有心头一怔。没错,这个地址GFW墙掉了,所以安装等待一段时间后会出...原创 2019-04-15 19:04:12 · 6748 阅读 · 0 评论