Code Monkey home page Code Monkey logo

p9c / gf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gogf/gf

0.0 2.0 0.0 66.58 MB

[mirror] GF(GoFrame) is a modular, lightweight, loosely coupled, high-performance application development framework written in Go. Supporting hot updates/restarting, multi-domain, multi-port, multi-service, HTTP/HTTPS, dynamic routing and many more features, it also provides a series of core components and dozens of practical modules.

Home Page: http://gf.johng.cn

License: MIT License

Go 99.93% Smarty 0.07%

gf's Introduction

GF(Go Frame)是一款模块化、松耦合、轻量级、高性能的Go语言Web开发框架。支持热重启、热更新、多域名、多端口、多服务、HTTP/HTTPS、动态路由等特性 ,并提供了Web服务开发的系列核心组件,如:Router、Cookie、Session、服务注册、配置管理、模板引擎、数据校验、分页管理、数据库ORM等等等等, 并且提供了数十个实用开发模块集,如:缓存、日志、时间、命令行、二进制、文件锁、对象池、连接池、数据编码、进程管理、进程通信、TCP/UDP组件、 并发安全容器、Goroutine池等等等等等等。

开源项目地址(仓库保持实时同步): GiteeGithub。 使用中有任何问题/建议,欢迎加入技术QQ群交流:116707870。 如有优秀的框架使用案例,欢迎联系作者将地址展示到项目库中,您的牛逼将被世人所瞻仰。

安装

go get -u gitee.com/johng/gf

限制

golang版本 >= 1.9.2

特点

  1. 轻量级、高性能,模块化、松耦合设计,丰富的开发模块;
  2. 热重启、热更新特性,并支持Web界面及命令行管理接口;
  3. 专业的技术交流群,完善的开发文档及示例代码,良好的中文化支持;
  4. 支持多种形式的服务注册特性,灵活高效的路由控制管理;
  5. 支持服务事件回调注册功能,可供选择的pprof性能分析模块;
  6. 支持配置文件及模板文件的自动检测更新机制,即修改即生效;
  7. 支持自定义日期时间格式的时间模块,类似PHP日期时间格式化;
  8. 强大的数据/表单校验模块,支持常用的40种及自定义校验规则;
  9. 强大的网络通信TCP/UDP组件,并提供TCP连接池特性,简便高效;
  10. 提供了对基本数据类型的并发安全封装,提供了常用的数据结构容器;
  11. 支持Go变量/Json/Xml/Yml/Toml任意数据格式之间的相互转换及创建;
  12. 强大的数据库ORM,支持应用层级的集群管理、读写分离、负载均衡,查询缓存、方法及链式ORM操作;
  13. 更多特点请查阅框架手册源码

文档

GoFrame开发文档:http://gf.johng.cn

使用

Hello World

package main

import (
    "gitee.com/johng/gf/g"
    "gitee.com/johng/gf/g/net/ghttp"
)

func main() {
    s := g.Server()
    s.BindHandler("/", func(r *ghttp.Request) {
        r.Response.Write("Hello World")
    })
    s.Run()
}

多域名支持

package main

import (
    "gitee.com/johng/gf/g"
    "gitee.com/johng/gf/g/net/ghttp"
)

func main() {
    s := g.Server()
    s.Domain("localhost1,localhost2").BindHandler("/", func(r *ghttp.Request) {
        r.Response.Write("localhostx")
    })
    s.Run()
}

多端口支持

package main

import (
    "gitee.com/johng/gf/g"
    "gitee.com/johng/gf/g/net/ghttp"
)

func main() {
    s := g.Server()
    s.BindHandler("/", func(r *ghttp.Request){
        r.Response.Writeln("go frame!")
    })
    s.SetPort(8080, 8081, 8082)
    s.Run()
}

路由控制

package main

import (
    "gitee.com/johng/gf/g"
    "gitee.com/johng/gf/g/net/ghttp"
)

func main() {
    s := g.Server()
    s.BindHandler("/order/:action/{page}.html", func(r *ghttp.Request){
        r.Response.Writef("action:%s, page:%s", r.Get("action"), r.Get("page"))
    })
    s.SetPort(8199)
    s.Run()
}

数据库ORM

ORM创建/关闭

// 获取默认配置的数据库对象(配置名称为"default")
db, err := gdb.New()
// 获取配置分组名称为"user-center"的数据库对象
db, err := gdb.New("user-center")
// 关闭数据库操作对象(丢回连接池对象复用)
db.Close()

单表/联表查询

// 查询多条记录并使用Limit分页
r, err := db.Table("user").Where("u.uid > ?", 1).Limit(0, 10).Select()
// 查询符合条件的单条记录(第一条)
r, err := db.Table("user u").LeftJoin("user_detail ud", "u.uid=ud.uid").Fields("u.*,ud.site").Where("u.uid=?", 1).One()
// 查询指定字段值
r, err := db.Table("user u").RightJoin("user_detail ud", "u.uid=ud.uid").Fields("ud.site").Where("u.uid=?", 1).Value()
// 分组及排序
r, err := db.Table("user u").InnerJoin("user_detail ud", "u.uid=ud.uid").Fields("u.*,ud.city").GroupBy("city").OrderBy("register_time asc").Select()
// 不使用john的联表查询
r, err := db.Table("user u,user_detail ud").Where("u.uid=ud.uid").Fields("u.*,ud.city").All()
// 不使用Fields方法指定查询字段时,默认查询为"*"
r, err := db.Table("user").Where("u.uid=1",).One()

更新/删除

// 更新
r, err := db.Table("user").Data(gdb.Map{"name" : "john2"}).Where("name=?", "john").Update()
r, err := db.Table("user").Data("name='john3'").Where("name=?", "john2").Update()
// 删除
r, err := db.Table("user").Where("uid=?", 10).Delete()
// Data数值方法的参数形式比较灵活
r, err := db.Table("user").Data(`name="john"`).Update()
r, err := db.Table("user").Data("name", "john").Update()
r, err := db.Table("user").Data(g.Map{"name" : "john"}).Update()

写入/保存

r, err := db.Table("user").Data(gdb.Map{"name": "john"}).Insert()
r, err := db.Table("user").Data(gdb.Map{"uid": 10000, "name": "john"}).Replace()
r, err := db.Table("user").Data(gdb.Map{"uid": 10001, "name": "john"}).Save()

事务操作

if tx, err := db.Begin(); err == nil {
    if r, err := tx.Table("user").Data(gdb.Map{"uid":1, "name": "john"}).Save(); err == nil {
        tx.Commit()
    } else {
        tx.Rollback()
    }

    fmt.Println(r, err)
}

...

更多特性及示例请查看官方开发文档:gf.johng.cn

gf's People

Contributors

gqcn avatar wenzi1 avatar shinxiang avatar chenyang351 avatar wxkj001 avatar zjfsdnu avatar garfieldkwong avatar

Watchers

James Cloos avatar l0k1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.