分类 Golang 中的文章

Gengine源码阅读 DataContext

数据结构概览 1 2 3 4 5 type DataContext struct { lockVars sync.Mutex // 对外部送进来的vars进行加锁 lockBase sync.Mutex // 对下面一行的`base`字段加锁 base map[string]reflect.Value // 存储各种类型的值, key是变量名, value是变量值, 变量值可以是任意类型, 例如:函数 } 上下文数据的增删查改 1 2 3 4 5 6 7 8 9 10 11 12 13 // 在base中添加一条数据,并将obj转换为reflect.Value类型 // 会使用localBase func (dc *DataContext) Add(key string, obj interface{}) // 批量删除base中的数据 // 会使用localBase func (dc *DataContext) Del(key string) // load一个动态库,并将动态库中提供给外部的接口全部写入base中 // 会使用localBase func (dc *DataContext) PluginLoader(absolutePathOfSO string) (string, plugin.……

阅读全文

`caarlos0/env`源码阅读

Tips: 建议先看下官方文档,如何使用env再看源码 项目信息 地址:https://github.com/caarlos0/env 描述:一个可以parse环境变量到go struct的简单的三方库 版本:tag: v6.8.0 源码阅读 入口函数(Parse) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // Parse parses a struct containing `env` tags and loads its values from // environment variables. func Parse(v interface{}, opts ...Options) error { return ParseWithFuncs(v, map[reflect.Type]ParserFunc{}, opts...) } // ParseWithFuncs is the same as `Parse` except it also allows the user to pass // in custom parsers.……

阅读全文