2020年9月

结构化日志方便查询

package main

import (
    "errors"

    "go.uber.org/zap"
)

func main() {
    // logger, err := zap.NewProduction()
    logger, err := zap.NewDevelopment()
    if err != nil {
        panic(err.Error())
    }
    logger.Info("hello world", zap.String("user", "咪了个猫"), zap.Int("age", 666))

    err = errors.New("我是一个错误")
    logger.Error("报错啦", zap.Error(err), zap.String("xxx", "我是一个参数"))

    logger.Info("hello world", zap.String("user", "咪了个猫"), zap.Error(err))
}


2020-09-22T16:51:33.156+0800    INFO    xxx3/main.go:15 hello world     {"user": "咪了个猫", "age": 666}
2020-09-22T16:51:33.156+0800    ERROR   xxx3/main.go:18 报错啦  {"error": "我是一个错误", "xxx": "我是一个参数"}
main.main
        /Users/wameidemao/Desktop/xxx3/main.go:18
runtime.main
        /usr/local/go/src/runtime/proc.go:204
2020-09-22T16:51:33.156+0800    INFO    xxx3/main.go:20 hello world     {"user": "咪了个猫", "error": "我是一个错误"}

智能家居

hc

https://github.com/brutella/hc

hc is a lightweight framework to develop HomeKit accessories in Go. It abstracts the HomeKit Accessory Protocol (HAP) and makes it easy to work with services and characteristics.

hc handles the underlying communication between HomeKit accessories and clients. You can focus on implementing the business logic for your accessory, without having to worry about the protocol.

https://luaunit.readthedocs.io/en/latest/

local lu = require("luaunit")

-- 注册单元测试函数 (函数必须以test开头)

function test_fun1()

end

function test_fun2()

end

-- 注册单元测试模块 (模块必须以test开头)

test_mod = {}

function test_mod:setUp()
    -- 调用模块测试函数前执行
end

function test_mod:tearDown()
    -- 调用模块测试函数后执行
end

function test_mod:test_fun1() -- 测试函数必须以test开头,并且使用:调用模式

end

function test_mod:test_fun2()

end

lu.LuaUnit.verbosity = 2
os.exit(lu.LuaUnit.run())

断言方法:
lu.assertEquals(a, b) -- 深度对比,包括 table
lu.assertNotEquals(a, b)
lu.assertEvalToTrue(a)
lu.assertEvalToFalse(a)
lu.assertTrue(a)
lu.assertFalse(b)
error(a)
assert(a)