随笔分类 -  go

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

termui golang 版本的终端dashboard
摘要:termui是构建在termbox-go之上的一个跨平台的完全可自定义的终端dashboard 以及widget 库,由blessed-contrib 以及tui-rs 启发 支持的特性 几个常见用例的预制小部件 轻松创建自定义小部件 在相对网格或绝对坐标中定位小部件 键盘,鼠标和终端大小调整事件 阅读全文

posted @ 2020-03-05 09:43 荣锋亮 阅读(2326) 评论(0) 推荐(0)

golang 条件编译
摘要:很多时候对于不同的平台需要编写不同的代码,可选的方式 build tag 参考格式 // +build 对于平台处理的例子 // +build linux,386 darwin,!cgo 文件后缀 参考格式 _$GOOS.go _$GOOS_$GOARCH.go 参考例子 mypkg_freebsd 阅读全文

posted @ 2020-02-02 13:12 荣锋亮 阅读(525) 评论(0) 推荐(0)

gox 简单灵活的golang 跨平台编译工具
摘要:gox 是使用简单,灵活的跨平台golang 编译工具,我们可以快速的生成多平台的可运行文件,和使用go build 类似 一个参考构建命令 gox -ldflags "-X main.version=${VERSION}" -output="build/{{.Dir}}_{{.OS}}_{{.Ar 阅读全文

posted @ 2020-01-31 19:33 荣锋亮 阅读(1132) 评论(0) 推荐(0)

golang pprof 简单使用
摘要:项目结构 ├── go.mod ├── go.sum ├── main.go ├── go.mod ├── go.sum ├── main.go ├── go.mod ├── go.sum ├── main.go ├── go.mod ├── go.sum ├── main.go ├── go.mo 阅读全文

posted @ 2019-12-27 14:46 荣锋亮 阅读(981) 评论(0) 推荐(0)

go.rice 强大灵活的golang 静态资源嵌入包
摘要:以前简单介绍过packr ,statik 等静态资源嵌入工具包的使用,go.rich 是一个与packr 类似的静态资源嵌入包,使用简单 功能强大 项目结构 golang mod go mod init github.com/rongfengliang/rice-app go mod init gi 阅读全文

posted @ 2019-11-05 15:52 荣锋亮 阅读(2178) 评论(0) 推荐(0)

几个golang 静态资源嵌入包
摘要:静态资源嵌入二进制文件中,可以方便我们的软件分发(只需要简单的二进制文件就可以了),目前大部分golang 的 web 应用都是使用类似的方法。 以下是收集到的一些常见方案 github.com/go-bindata/go-bindata go-bindata 的使用方法是先生成代码,然后使用提供的 阅读全文

posted @ 2019-11-05 13:53 荣锋亮 阅读(2298) 评论(0) 推荐(0)

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

posted @ 2019-10-30 17:31 荣锋亮 阅读(1018) 评论(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 荣锋亮 阅读(622) 评论(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 荣锋亮 阅读(4114) 评论(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 荣锋亮 阅读(975) 评论(0) 推荐(0)

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

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

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

posted @ 2019-10-15 13:50 荣锋亮 阅读(524) 评论(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 荣锋亮 阅读(917) 评论(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 荣锋亮 阅读(778) 评论(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 荣锋亮 阅读(788) 评论(0) 推荐(0)

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

posted @ 2019-10-15 11:21 荣锋亮 阅读(1152) 评论(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 荣锋亮 阅读(957) 评论(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 荣锋亮 阅读(992) 评论(0) 推荐(0)

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

posted @ 2019-10-15 09:18 荣锋亮 阅读(797) 评论(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 荣锋亮 阅读(1502) 评论(0) 推荐(0)

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

导航