representing zones time go

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

Go每日一库之36:nutsdb

## 简介 [`nutsdb`](https://github.com/xujiajun/nutsdb)是一个完全由 Go 编写的简单、快速、可嵌入的持久化存储。`nutsdb`与我们之前介绍过的[`buntdb`](https://go-quiz.github.io/2020/03/21/goda ......
nutsdb

Go每日一库之37:sqlc

## 简介 在 Go 语言中编写数据库操作代码真的非常痛苦!`database/sql`标准库提供的都是比较底层的接口。我们需要编写大量重复的代码。大量的模板代码不仅写起来烦,而且还容易出错。有时候字段类型修改了一下,可能就需要改动很多地方;添加了一个新字段,之前使用`select *`查询语句的地 ......
sqlc

Go每日一库之47:cli

## 简介 [`cli`](https://github.com/urfave/cli)是一个用于构建命令行程序的库。我们之前也介绍过一个用于构建命令行程序的库[`cobra`](https://go-quiz.github.io/2020/01/17/godailylib/cobra/)。在功能上 ......
cli

Go每日一库之48:cron

## 简介 [`cron`](https://github.com/robfig/cron)一个用于管理定时任务的库,用 Go 实现 Linux 中`crontab`这个命令的效果。之前我们也介绍过一个类似的 Go 库——[`gron`](https://go-quiz.github.io/2020 ......
cron

Go每日一库之63:ants

## 简介 处理大量并发是 Go 语言的一大优势。语言内置了方便的并发语法,可以非常方便的创建很多个轻量级的 goroutine 并发处理任务。相比于创建多个线程,goroutine 更轻量、资源占用更少、切换速度更快、无线程上下文切换开销更少。但是受限于资源总量,系统中能够创建的 goroutin ......
ants

Go每日一库之65:tunny

## 简介 之前写过一篇文章介绍了`ants`这个 goroutine 池实现。当时在网上查看相关资料的时候,发现了另外一个实现[`tunny`](https://github.com/Jeffail/tunny)。趁着时间相近,正好研究一番。也好比较一下这两个库。那就让我们开始吧。 ## 快速开始 ......
tunny

Go每日一库之66:bubbletea

## 简介 `[bubbletea](https://github.com/charmbracelet/bubbletea)`是一个简单、小巧、可以非常方便地用来编写 TUI(terminal User Interface,控制台界面程序)程序的框架。内置简单的事件处理机制,可以对外部事件做出响应, ......
bubbletea

Go每日一库之68:dateparse

## 简介 不管什么时候,处理时间总是让人头疼的一件事情。因为时间格式太多样化了,再加上时区,夏令时,闰秒这些细枝末节处理起来更是困难。所以在程序中,涉及时间的处理我们一般借助于标准库或第三方提供的时间库。今天要介绍的[`dateparse`](https://github.com/araddon/ ......
dateparse

Go每日一库之31:plot(图表绘制)

## 简介 本文介绍 Go 语言的一个非常强大、好用的绘图库——`[plot](https://github.com/gonum/plot)`。`plot`内置了很多常用的组件,基本满足日常需求。同时,它也提供了定制化的接口,可以实现我们的个性化需求。`plot`主要用于将数据可视化,便于我们观察、 ......
图表 plot

Go每日一库之64:ants(源码赏析)

## 简介 继上一篇[Go 每日一库之 ants](https://go-quiz.github.io/2021/06/03/godailylib/ants),这篇文章我们来一起看看`ants`的源码。 ## `Pool` 通过上篇文章,我们知道`ants`池有两种创建方式: - `p, _ := ......
源码 ants

Go每日一库之67:ozzo-validation

## 简介 [`ozzo-validation`](https://github.com/go-ozzo/ozzo-validation)是一个非常强大的,灵活的数据校验库。与其他基于 struct tag 的数据校验库不同,`ozzo-validation`认为 struct tag 在使用过程中 ......
ozzo-validation validation ozzo

Go每日一库之49:mapstructure

## 简介 [`mapstructure`](https://github.com/mitchellh/mapstructure)用于将通用的`map[string]interface{}`解码到对应的 Go 结构体中,或者执行相反的操作。很多时候,解析来自多种源头的数据流时,我们一般事先并不知道他 ......
mapstructure