随笔分类 -  go

上一页 1 ··· 4 5 6 7 8 9 10 下一页

使用viper 进行golang 应用的配置管理
摘要:viper 是一个强大的golang 配置管理包,支持多种配置格式内容的读取,同时支持读取key/value 存储的数据 而且不只是读取内容 ,同时也包含了,配置的写入操作。 以下是一个简单的demo,同时使用docker 运行 项目结构 项目使用go mod 进行包的管理 目录结构 ├── Doc 阅读全文

posted @ 2019-10-30 17:31 荣锋亮 阅读(994) 评论(0) 推荐(0) 编辑

systemd socket activation golang demo
摘要:service define rongapp.service [Unit] Description=rong Hello World HTTP Requires=network.target rongapp.socket After=multi-user.target ​ [Service] Typ 阅读全文

posted @ 2019-10-30 10:02 荣锋亮 阅读(611) 评论(0) 推荐(0) 编辑

golang 几个好用的cli package
摘要:cli 开发在golang 的软件开发中占用很大,同时开源的比较好用的cli也很多,以下是整理的几个cli github.com/spf13/cobra 这个比较有名了, 好多框架都使用了这个 以下是一个简单的使用 代码 package main ​ import ( "github.com/spf 阅读全文

posted @ 2019-10-16 14:27 荣锋亮 阅读(3991) 评论(0) 推荐(1) 编辑

ent 基本使用十九 事务处理
摘要:ent 生成的代码中client 提供了比较全的事务处理 启动单个事务进行处理 // GenTx generates group of entities in a transaction. func GenTx(ctx context.Context, client *ent.Client) err 阅读全文

posted @ 2019-10-15 16:00 荣锋亮 阅读(899) 评论(0) 推荐(0) 编辑

ent 基本使用十四 edge
摘要:edge 在ent 中属于比较核心,同时也是功能最强大的,ent 提供了比较强大的关系模型 快速使用 参考图 以上包含了两个通过边定义的关系 pets/owner: user package schema ​ import ( "github.com/facebookincubator/ent" " 阅读全文

posted @ 2019-10-15 14:02 荣锋亮 阅读(1335) 评论(0) 推荐(0) 编辑

ent 基本使用十八 查询谓词
摘要:ent 生成的代码包含了比较完整的查询谓词 字段谓词 Bool: =, != Numeric: =, !=, >, <, >=, <=, IN, NOT IN Time: =, !=, >, <, >=, <= IN, NOT IN String: =, !=, >, <, >=, <= IN, N 阅读全文

posted @ 2019-10-15 13:50 荣锋亮 阅读(494) 评论(0) 推荐(0) 编辑

ent 基本使用十七 分页与排序
摘要:ent 提供了方便的数据分页以及排序处理 limit 分页 users, err := client.User. Query(). Limit(n). All(ctx) users, err := client.User. Query(). Limit(n). All(ctx) users, err 阅读全文

posted @ 2019-10-15 13:42 荣锋亮 阅读(848) 评论(0) 推荐(0) 编辑

ent 基本使用十六 聚合
摘要:ent 提供了聚合处理 一个group by + 聚合的处理(age以及name字段) package main ​ import ( "context" ​ "<project>/ent" "<project>/ent/user" ) ​ func Do(ctx context.Context, 阅读全文

posted @ 2019-10-15 13:39 荣锋亮 阅读(716) 评论(0) 推荐(0) 编辑

ent 基本使用十五 一个图遍历的例子
摘要:以下是来自官方的一个user group pet 的查询demo 参考关系图 环境准备 docker-compose mysql 环境 version: "3" services: mysql: image: mysql:5.7.16 ports: - 3306:3306 command: --ch 阅读全文

posted @ 2019-10-15 13:33 荣锋亮 阅读(768) 评论(0) 推荐(0) 编辑

ent 基本使用十三 debug 模式
摘要:ent 生成的代码client 包中包含了一个方便的方法Debug(), 记得昨天我为了查看生成的sql 查询通过配置mysql 启用慢查询,同时设置记录慢查询为0,实际上client Debug 方法使用了builder 的模式,我们通过Debug 方法 可以直接就方便的输出生成的sql 参考代码 阅读全文

posted @ 2019-10-15 11:21 荣锋亮 阅读(991) 评论(0) 推荐(0) 编辑

ent 基本使用十二 字段
摘要:字段或者属性,在schema中是定点的属性,比如user 包含4个字段age,name,username,created_at 图表展示如下: 代码描述 package schema ​ import ( "time" ​ "github.com/facebookincubator/ent" "gi 阅读全文

posted @ 2019-10-15 10:15 荣锋亮 阅读(863) 评论(0) 推荐(0) 编辑

ent 基本使用十一 sql.DB 集成
摘要:这个功能是github中大家提的比较多的一个,所以官方也暴露了相关的api 配置sql.DB 一种方式 package main ​ import ( "time" ​ "<your_project>/ent" "github.com/facebookincubator/ent/dialect/sq 阅读全文

posted @ 2019-10-15 09:23 荣锋亮 阅读(969) 评论(0) 推荐(0) 编辑

ent 基本使用十 数据库迁移
摘要:ent 提供了便捷的数据库迁移处理,我们可以直接使用生成的代码进行操作,同时代码也提供了比较全的运行选项 默认迁移处理 我们通过create 进行资源创建,默认是append-only 模式 ,以为着只会创建新的表以及索引 ,同时添加列到表,或者 扩展现有列的数据类型 if err := clien 阅读全文

posted @ 2019-10-15 09:18 荣锋亮 阅读(737) 评论(0) 推荐(0) 编辑

ent 基本使用九 代码生成
摘要:ent 提供了cli 工具,可以方便我们进行schema 以及代码生成,同时目前提供的cli已经够用了 安装 cli go get github.com/facebookincubator/ent/cmd/entc go get github.com/facebookincubator/ent/cm 阅读全文

posted @ 2019-10-15 08:54 荣锋亮 阅读(1433) 评论(0) 推荐(0) 编辑

ent 基本使用八 索引
摘要:我们可以在ent 的schema 中定义index 可以方便的控制数据约束,使用索引可以加速我们的访问以及数据的唯一性处理 配置字段索引 多字段索引 package schema ​ import ( "github.com/facebookincubator/ent" "github.com/fa 阅读全文

posted @ 2019-10-14 23:03 荣锋亮 阅读(499) 评论(0) 推荐(0) 编辑

ent 基本使用七 Config
摘要:通过config 我们可以自定义表相关的选项 参考配置 package schema ​ import ( "github.com/facebookincubator/ent" "github.com/facebookincubator/ent/schema/field" ) ​ type User 阅读全文

posted @ 2019-10-14 21:21 荣锋亮 阅读(337) 评论(0) 推荐(0) 编辑

ent 基本使用六 Mixin
摘要:ent 的Mixin 可以让我们服用已有的schema Mixin 接口说明 type Mixin interface { Fields() []ent.Field } type Mixin interface { Fields() []ent.Field } type Mixin interfac 阅读全文

posted @ 2019-10-14 21:13 荣锋亮 阅读(679) 评论(0) 推荐(0) 编辑

ent 基本使用五 schema介绍
摘要:ent 提供了自动生成schema 但是,我们可以基于生成schema 进行扩展,schema 主要包含以下配置 实体的字段(或者属性)比如 user 的name 以及age 实体的边(关系),比如user 的groups user 的friends 数据库选项,所以以及唯一索引 一个简单的sche 阅读全文

posted @ 2019-10-14 21:02 荣锋亮 阅读(726) 评论(0) 推荐(0) 编辑

ent 基本使用四 图遍历查询
摘要:接上文,我们已经创建了基本的关系以及表实体,以下是通过图方式的查询 参考关系图 代码处理 创建图数据 func CreateGraph(ctx context.Context, client *ent.Client) error { // first, create the users. a8m, 阅读全文

posted @ 2019-10-14 20:45 荣锋亮 阅读(562) 评论(0) 推荐(0) 编辑

ent 基本使用 三 边(关系处理)
摘要:ent 提供了图查询的能力,实际上在关系数据库中的表现就是relation,以下代码接前文 添加边(关系) 添加schema entc init Car Group entc init Car Group entc init Car Group entc init Car Group entc in 阅读全文

posted @ 2019-10-14 19:39 荣锋亮 阅读(1307) 评论(0) 推荐(0) 编辑

上一页 1 ··· 4 5 6 7 8 9 10 下一页

导航