Tech

Gin-Gonic 框架中间件原理与应用

published on
在 Go 的世界里, web 框架简直多如牛毛. 前有自带电池的标准库(net/http), 后有简洁优雅的 Gin-Gonic(以下简称 Gin), 再有全栈开发一枝花 Beego, 等等不可胜数. 使用 Go 有一段时间了, web 开发一直用的 Gin. Gin 的思想和 Python 框架 Flask 有颇多相似之处, 可以称作 微框架 . Gin 包括以下几个主要的部分: 设计精巧的路由/中间件系统; 简单好用的核心上下文 Context; 附赠工具集(JSON/XML 响应, 数据绑定与校验等). 本文意在探究 Gin 中间件的执行原理. 我们先看如下的 Hello World 版 Gin 程序: package main import ( "log" "net/http" "github.com/gin-gonic/gin" ) func main() { r := gin.Default() r.GET("/ping", func(c *gin.Context) { c.String(http.StatusOK, "%s", "pong!") }) if err := r. Read More...

PostgreSQL 10 JSON 全文检索(译)

published on
译文版权@归原文所有. 这是对 JSON 数据的又一个很酷的补充. 现在我们可以轻松地添加 json 值的全文搜索. 一个它如何运作的快速例子: $ select id, jsonb_pretty(payload) from test; id | jsonb_pretty ----+------------------------------------------------------------------------------------------------------------- 1 | { + | "glossary": { + | "title": "example glossary", + | "GlossDiv": { + | "title": "S", + | "GlossList": { + | "GlossEntry": { + | "ID": "SGML", + | "Abbrev": "ISO 8879:1986", + | "SortAs": "SGML", + | "Acronym": "SGML", + | "GlossDef": { + | "para": "A meta-markup language, used to create markup languages such as DocBook. Read More...

Conditional expressions in Postgres

published on
A simple example from Postgres offical documents: SELECT * FROM test; a --- 1 2 3 SELECT a, CASE WHEN a=1 THEN 'one' WHEN a=2 THEN 'two' ELSE 'other' END FROM test; a | case ---+------- 1 | one 2 | two 3 | other It is based on this form: CASE WHEN condition THEN result [WHEN ...] [ELSE result] END It is very convenient in aggregation functions, just think table foo below: Read More...

Emacs is a habit

published on
What is Emacs EMACS may stand for Editing MACroS, but it has some more creative definitions. Here they are. Emacs Makes A Computer Slow Emacs May Annihilate Command Structures Evenings, Mornings, And a Couple of Saturdays Ever Made A Control-key Setup? Elephantine Memory Absolutely Considered Sine que non Emacs Makers Are Crazy Sickos … My road to mutiny Interactive Mode I used Vim more than three years before Emacs, so I think I’m very familiar with it. Read More...