newticker go

Go每日一库之100:websocket

Go语言标准包里面没有提供对WebSocket的支持,但是在由官方维护的go.net子包中有对这个的支持,需要独立下载。 **Go websocket package 下载地址:** `http://code.google.com/p/go.net/websocket ` **Go get 命令下载 ......
websocket 100

Go每日一库之101:swagger

一份清晰明了的接口文档能够极大地提高前后端双方的沟通效率和开发效率。本文将介绍如何使用swagger生成接口文档。 # Swagger介绍 `Swagger`是全球最大的`OpenAPI`规范(OAS)API开发工具框架,支持从设计和文档到测试和部署的整个API生命周期的开发 `Swagger`是目 ......
swagger 101

Go每日一库之102:grpcurl

[grpcurl](https://github.com/fullstorydev/grpcurl)是一个命令行工具,使用它可以在命令行中访问gRPC服务,就像使用curl访问http服务一样。 ## 准备 **在gRPC服务中注册reflection服务:** gRPC服务是使用Protobuf( ......
grpcurl 102

Go每日一库之107:errors

> 目前实现最优雅,打印堆栈良好的错误包。 # 下载安装 `go get -x github.com/pkg/errors` # 主要函数 ```go // 新生成一个错误, 带堆栈信息 func New(message string) error //只附加新的信息 func WithMessag ......
errors 107

Go每日一库之106:hystrix(熔断)

## 背景 随着微服务的流行,服务之间的调用可能变得越来越复杂,一个业务流程可能需要调用五六个甚至更多服务,这就会导致,假设某个服务出现问题,严重可能出现服务器负载过高,导致服务雪崩的现象。 因此为了防止此现象的发生,就需要考虑服务熔断机制,根据自身业务的需求,将其应用到服务中。 `什么是熔断`:可 ......
hystrix 106

Go每日一库之105:juju%2Fratelimit

限流又称为流量控制(流控),通常是指限制到达系统的并发请求数,常用的限流算法主要有漏洞和令牌桶。 ### 令牌桶 令牌桶其实和漏桶的原理类似,令牌桶按固定的速率往桶里放入令牌,并且只要能从桶里取出令牌就能通过,令牌桶支持突发流量的快速处理。 ![每日一库之105:juju%2Fratelimit-0 ......
2Fratelimit Fratelimit juju 105

Go每日一库之69:resty

## 简介 [`resty`](https://github.com/go-resty/resty)是 Go 语言的一个 HTTP client 库。`resty`功能强大,特性丰富。它支持几乎所有的 HTTP 方法(GET/POST/PUT/DELETE/OPTION/HEAD/PATCH等),并 ......
resty

Go每日一库之70:termtables

## 简介 今天学个简单点的,[`termtables`](github.com/scylladb/termtables)处理表格形式数据的输出。适用于随时随地的输出一些状态或统计数据,便于观察和调试。是一个很小巧的工具库。我在学习[`dateparse`](https://go-quiz.gith ......
termtables

Go每日一库之85:freecache

# [freecache](https://github.com/coocood/freecache) ## 一句话描述 Go缓存库,具有零GC开销和高并发性能 ## 简介 ### freecache是什么? 使用FreeCache,您可以在内存中缓存无限数量的对象,而不会增加延迟和降低吞吐量。 # ......
freecache

Go每日一库之86:zerolog

## [zerolog](https://github.com/rs/zerolog) ## 什么是 Zerolog ? zerolog 包提供了一个专门用于 JSON 输出的简单快速的Logger。 zerolog 的 API 旨在为开发者提供出色的体验和令人惊叹的[性能](https://git ......
zerolog

Go每日一库之87:zap

## [⚡ZAP](https://github.com/uber-go/zap) ## 简介 ### zap 是什么? [⚡ZAP](https://github.com/uber-go/zap) 是uber 开源的提供快速,结构化,高性能的日志记录包。 ### zap 高性能体现在哪里? 在介绍 ......
zap

Go每日一库之73:gorilla-mux

## 简介 [`gorilla/mux`](https://github.com/gorilla/mux)是 gorilla Web 开发工具包中的路由管理库。gorilla Web 开发包是 Go 语言中辅助开发 Web 服务器的工具包。它包括 Web 服务器开发的各个方面,有表单数据处理包[`g ......
gorilla-mux gorilla mux

Go每日一库之74:gorilla-handlers

## 简介 上一篇文章中,我们介绍了 gorilla web 开发工具包中的路由管理库[`gorilla/mux`](https://github.com/gorilla/mux),在文章最后我们介绍了如何使用中间件处理通用的逻辑。在日常 Go Web 开发中,开发者遇到了很多相同的中间件需求,[g ......
gorilla-handlers handlers gorilla

Go每日一库之75:gorilla-schema

## 简介 [`gorilla/schema`](https://github.com/gorilla/schema) 是 gorilla 开发工具包中用于处理表单的库。它提供了一个简单的方式,可以很方便地将表单数据转为结构体对象,或者将结构体对象转为表单数据。 ## 快速使用 本文代码使用 Go ......
gorilla-schema gorilla schema

Go每日一库之72:net-http(基础和中间件)

## 简介 几乎所有的编程语言都以`Hello World`作为入门程序的示例,其中有一部分以编写一个 Web 服务器作为实战案例的开始。每种编程语言都有很多用于编写 Web 服务器的库,或以标准库,或通过第三方库的方式提供。Go 语言也不例外。本文及后续的文章就去探索 Go 语言中的各个Web 编 ......
中间件 net-http 基础 http net

Go - Using Log Levels

Examples of log levels from high to low are: • Fatal • Error• Warn • Info • Debug To set up log levels for your logs, you can add the level to each li ......
Levels Using Log Go

Go - Logging to File

Problem: You want to log events to a logfile instead of standard error. Solution: Use the SetOutput function to set the log to write to a file. You us ......
Logging File Go to

Go - Change What Is Being Logged by the Standard Logger

Problem: You want to change what the standard logger logs. Solution: Use the SetFlags function to set flags and add fields to each log line. The defau ......
Standard Change Logged Logger Being

Go - logging

The log package provides several functions that allow you to write logs. In particular, there are three sets of functions:Print • Prints the logs to t ......
logging Go

Go - Inspecting Errors

Problem: You want to check for specific errors or specific types of errors. Solution: Use the errors.Is and errors.As functions. The errors.Is functio ......
Inspecting Errors Go

Go - Wrapping an Error with Other Errors

Problem: You want to provide additional information and context to an error you receive before returning it as another error. Solution: Wrap the error ......
Wrapping Errors Error Other with

Go - Creating Customized Errors

Problem: You want to create custom errors to communicate more information about the error encountered. Solution: Create a new string - based error or ......
Customized Creating Errors Go

Go - Simplifying Repetitive Error Handling

Problem: You want to reduce the number of lines of repetitive error - handling code. Solution: Use helper functions to reduce the number of lines of r ......
Simplifying Repetitive Handling Error Go

Go - Using Multiple Versions of the Same Dependent Packages

Problem: You want to use multiple versions of the same dependent packages in your code. Solution: Use the replace directive in the go.mod file to rena ......
Dependent Multiple Packages Versions Using

Go - Requiring Local Versions of Dependent Packages

Problem: You want to use local versions of the dependent packages. Solution: Set up Go to use a vendor directory by running go mod vendor. Local versi ......
Dependent Requiring Packages Versions Local

Go每日一库之33:go-app

## 简介 [`go-app`](https://github.com/maxence-charriere/go-app)是一个使用 Go + WebAssembly 技术编写**渐进式 Web 应用**的库。WebAssembly 是一种可以运行在现代浏览器中的新式代码。近两年来,WebAssem ......
go-app app go

Go每日一库之29:gopsutil

## 简介 `gopsutil`是 Python 工具库[`psutil`](https://github.com/giampaolo/psutil) 的 Golang 移植版,可以帮助我们方便地获取各种系统和硬件信息。`gopsutil`为我们屏蔽了各个系统之间的差异,具有非常强悍的可移植性。有了 ......
gopsutil

Go每日一库之32:gron

## 简介 [`gron`](https://github.com/roylee0704/gron)是一个比较小巧、灵活的定时任务库,可以执行定时的、周期性的任务。`gron`提供简洁的、并发安全的接口。我们先介绍`gron`库的使用,然后简单分析一下源码。 ## 快速使用 先安装: ```bash ......
gron

Go每日一库之34:zap

## 简介 在很早之前的文章中,我们介绍过 Go 标准日志库[`log`](https://go-quiz.github.io/2020/02/07/godailylib/log/)和结构化的日志库[`logrus`](https://go-quiz.github.io/2020/02/07/god ......
zap

Go每日一库之35:zerolog

## 简介 每个编程语言都有很多日志库,因为记录日志在每个项目中都是必须的。前面我们介绍了标准日志库[`log`](https://go-quiz.github.io/2020/02/07/godailylib/log/)、好用的[`logrus`](https://go-quiz.github.i ......
zerolog