gin-restful基于 gin 的 restful api 开发框架
# gin http restful项目生成 # 快速入门 go version > 1.2(应用go mod) git clone https://github.com/go-libraries/gin-restful cd gin-restful chmod +x ./build.sh $GOBIN/createGinProject -package=项目名 -path=项目路径 # 生成项目基本结构 ```go -base 基础文件 -config config.ini -handlers http处理回调 -logs 日志文件目录 -models 模型文件 -processes 可以理解为控制器对象 -routers 路由文件 go.mod main.go Readme.md ``` # 参数详解 ```go Usage of createMangoProject: -dsn string connection info names dsn -h this help -help this help -package string package name use all project -path string project build in this path -port string port ``` # 二次开发详解 ## 控制器 1. 可以在services中书写新的控制器 ```go type UserSaveService struct { base.Controller Account *UserSaveRequest } func (u *UserSaveService) Decode() base.IError { // 解析 输入字段 如下 u.Account = &UserSaveRequest{&models.UserAccount{}, ""} if bt, err := u.Ctx.GetRawData(); err == nil { if err := json.Unmarshal(bt, u.Account); err != nil { return base.NewError(err) } } else { return base.NewError(err) } return nil } func (u *UserSaveService) Process() base.IError { //todo:执行业务过程 return nil } ``` 2. 可以在controllers中注入执行方法 ```go func SaveUser(c *gin.Context) { p := &base.Controller{} p.ServiceFun = func(u *base.DefaultService) base.IError { u.Data = "hello world" return nil } base.RunService(p, c) } ``` ## 路由 路由可以开发二次中间件功能 ```go package routers import ( "github.com/gin-gonic/gin" "time" "{{package}}/base" ) type Route struct { Name string Method string Path string HandlerFunc gin.HandlerFunc } func calTime(fn func(c *gin.Context)) func(c *gin.Context) { return func(c *gin.Context) { start := time.Now() fn(c) base.Log.Printf("Done in %v (%s %s)\n", time.Since(start), c.Request.Method, c.Request.URL.Path) } } func init() { //Router.GET("/", func(c *gin.Context) { // time.Sleep(5 * time.Second) // c.String(http.StatusOK, "Welcome Gin Server") //}) for _, route := range getUserRoutes() { handle := calTime(route.HandlerFunc) base.Gin.Handle(route.Method, route.Path, handle) } //todo: add other Routes } ``` ## 模型 默认使用gorm作为数据驱动,如果初始化--dsn项目不为空,会自动将该db下表生成模型并提供基础方法 外部库详见 [外部库-模型生成器](https://github.com/go-libraries/genModels) ## 文档 文档使用swagger进行配置,可以一键生成 详见
评论
Kanary基于 Kotlin 的可扩展 RESTful API Web 框架
Kanary是一个用于构建可扩展和富有表现力的的RESTfulAPI的KotlinWeb框架。fun main(args: Array<String>) { val app = Ka
Kanary基于 Kotlin 的可扩展 RESTful API Web 框架
0
Kanary基于 Kotlin 的可扩展 RESTful API Web 框架
Kanary 是一个用于构建可扩展和富有表现力的的 RESTful API 的 Kotlin Web
Kanary基于 Kotlin 的可扩展 RESTful API Web 框架
0
TPRTPR---基于thinkphp5的restful接口框架
TPR---基于thinkphp5的restful接口框架主要基于thinkphp5的restful
TPRTPR---基于thinkphp5的restful接口框架
0
Surge基于 Accelerate 框架的 API
Surge是一个基于Accelerate框架和C语言开发,用于进行矩阵运算、数学信号处理和图像处理的
Surge基于 Accelerate 框架的 API
0
Surge基于 Accelerate 框架的 API
Surge是一个基于Accelerate框架和C语言开发,用于进行矩阵运算、数学信号处理和图像处理的API。换句话说,就是可以非常快速的处理数学、语音和图像信号。代码示例:用法计算总和[Double]
Surge基于 Accelerate 框架的 API
0
SlimCustom轻量级RESTFul开发框架
轻量级RESTFul开发框架SlimCustom可以帮助你快速编写简单但功能强大的web应用和API。特色:HTTP路由,中间件,PSR-7支持,依赖注入,门面模式,模型自动验证,字段预处理,多进程任
SlimCustom轻量级RESTFul开发框架
0
PhpBoot快速开发 RESTful 接口的框架
PhpBootPhpBoot 是为快速开发 RESTful API 设计的 PHP 框架。它可以帮助
PhpBoot快速开发 RESTful 接口的框架
0
TPRTPR---基于thinkphp5的restful接口框架
TPR---基于thinkphp5的restful接口框架主要基于thinkphp5的restful设计风格的接口框架。专为接口开发而设计做高并发、高可用、易扩展的php接口开发的必备首选交流QQ群:
TPRTPR---基于thinkphp5的restful接口框架
0