go-web-starter

module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2020 License: Apache-2.0

README

go-web-start

介绍

go-web-start是一个简化go web开发的工具集,包含:

  1. web基础框架
  2. 数据库操作ORM
  3. rest请求和应答日志
  4. 统一异常捕捉
  5. 其他

使用

安装
go get github.com/xfali/go-web-start
配置

示例

{
  "Env": "dev",
  "LogResponse": true,
  "LogRequestBody": true,
  "LogLevel": 1,
  "LogInnerLevel": 1,
  "LogClient": true,
  "ServerPort": 8080,

  "DataSources": {
    "default": {
      "DriverName": "mysql",
      "DriverInfo": "root:123@tcp(localhost:3306)/test?charset=utf8",
      "MaxConn": 1000,
      "MaxIdleConn": 500,
      "ConnMaxLifetime": 15000
    }
  }
}
数据库
  1. 集成gobatis

  2. 配合gobatis-cmd使用,可大幅提高开发效率。

  3. 分页:

使用pagehelper

集成方式:

第一步:初始化时配置FactoryBuilder

    web.SetFactoryBuilder(func(source *config.DataSource) factory.Factory {
        return pagehelper.New(datasource.DefaultBuilder(source))
    })

第二步:使用需要分页的查询语句时:

    sess := datasource.Get("default")
                .NewSession()
                .SetContext(pagehelper.StartPage(page, pageSize, context.Background()))
    sess.Select("SELECT * FROM TBL_TEST").Param().Result(&ret)
    //或者使用gobatis-cmd自动生成的操作方法:
    //ret, err := mapper.SelectTestTable(sess, TestTable{})

Directories

Path Synopsis
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL