mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +08:00
完成gbinary示例,完善README
This commit is contained in:
parent
a16314aa78
commit
a6ace7ff53
11
README.MD
11
README.MD
@ -5,8 +5,8 @@
|
||||
## 介绍
|
||||
gf(Go Frame)是一款为Web服务及网络服务开发设计的,模块化、低耦合、轻量级的Go语言开发框架。
|
||||
实现了通用的HTTP/TCP/UDP Server,并提供了Web服务开发的系列核心组件,
|
||||
包括:MVC、Cookie、Session、模板引擎、路由控制、配置管理、数据校验、数据库操作等等,
|
||||
并且提供了数十个实用开发模块,包括:缓存模块、日志模块、JSON模块、命令行模块、环境变量模块、并发安全容器、Goroutine池等等。
|
||||
包括:MVC、Cookie、Session、模板引擎、路由控制、配置管理、数据校验、数据库操作(ORM)等等,
|
||||
并且提供了数十个实用开发模块,包括:缓存模块、日志模块、JSON模块、命令行模块、二进制模块、环境变量模块、并发安全容器、Goroutine池等等。
|
||||
|
||||
gf是开源的,免费的,基于MIT协议进行分发,开源项目地址:https://gitee.com/johng/gf
|
||||
|
||||
@ -24,10 +24,11 @@ package main
|
||||
import "gitee.com/johng/gf/g/net/ghttp"
|
||||
|
||||
func main() {
|
||||
ghttp.GetServer().BindHandler("/", func(r *ghttp.Request){
|
||||
s := ghttp.GetServer()
|
||||
s.BindHandler("/", func(r *ghttp.Request){
|
||||
r.Response.WriteString("Hello World!")
|
||||
})
|
||||
ghttp.GetServer().Run()
|
||||
s.Run()
|
||||
}
|
||||
```
|
||||
## 文档
|
||||
@ -54,7 +55,9 @@ func main() {
|
||||
* [时间模块](https://www.kancloud.cn/johng/gf/494387)
|
||||
* [JSON模块](https://www.kancloud.cn/johng/gf/494388)
|
||||
* [命令行模块](https://www.kancloud.cn/johng/gf/494389)
|
||||
* [二进制模块](https://www.kancloud.cn/johng/gf/500342)
|
||||
* [HTTP客户端](https://www.kancloud.cn/johng/gf/499674)
|
||||
* [Goroutine池](https://www.kancloud.cn/johng/gf/504458)
|
||||
* [环境变量模块](https://www.kancloud.cn/johng/gf/494390)
|
||||
* [文件管理模块](https://www.kancloud.cn/johng/gf/494391)
|
||||
* [并发安全容器](https://www.kancloud.cn/johng/gf/494392)
|
||||
|
@ -270,7 +270,7 @@ func EncodeBitsToBytes(bits []Bit) []byte {
|
||||
}
|
||||
|
||||
// 解析为int
|
||||
func DecodeBitsToInt(bits []Bit) int {
|
||||
func DecodeBits(bits []Bit) int {
|
||||
v := int(0)
|
||||
for _, i := range bits {
|
||||
v = v << 1 | int(i)
|
||||
|
@ -13,7 +13,7 @@ func main() {
|
||||
// 网关编码
|
||||
bits := make([]gbinary.Bit, 0)
|
||||
for i := 0; i < count; i++ {
|
||||
bits = gbinary.EncodeBits(bits, uint(status), 2)
|
||||
bits = gbinary.EncodeBits(bits, status, 2)
|
||||
}
|
||||
buffer := gbinary.EncodeBitsToBytes(bits)
|
||||
fmt.Println("buffer length:", len(buffer))
|
||||
|
@ -14,13 +14,15 @@ func main() {
|
||||
|
||||
// 编码
|
||||
bits := make([]gbinary.Bit, 0)
|
||||
bits = gbinary.EncodeBits(bits, uint(hash), 64)
|
||||
bits = gbinary.EncodeBits(bits, uint(klen), 8)
|
||||
bits = gbinary.EncodeBits(bits, uint(vlen), 24)
|
||||
bits = gbinary.EncodeBits(bits, uint(offset), 40)
|
||||
bits = gbinary.EncodeBits(bits, hash, 64)
|
||||
bits = gbinary.EncodeBits(bits, klen, 8)
|
||||
bits = gbinary.EncodeBits(bits, vlen, 24)
|
||||
bits = gbinary.EncodeBits(bits, offset, 40)
|
||||
buffer := gbinary.EncodeBitsToBytes(bits)
|
||||
fmt.Println("meta length:", len(buffer))
|
||||
|
||||
/* 然后将二进制数据存储到元数据文件中,查询数据时涉及到的元数据解码操作如下 */
|
||||
|
||||
// 解码
|
||||
metabits := gbinary.DecodeBytesToBits(buffer)
|
||||
fmt.Println("hash :", gbinary.DecodeBits(metabits[0 : 64]))
|
||||
|
Loading…
Reference in New Issue
Block a user