V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
niuoh
V2EX  ›  问与答

用 golang 造了个 curd api 的轮子

  •  
  •   niuoh · Dec 14, 2018 · 1343 views
    This topic created in 2696 days ago, the information mentioned may be changed or developed.

    最近需要写个接口的项目 准备顺便熟悉一下 golang
    在 github 找了下 golang 的 resetful 接口项目 大部分需要对每张表定义一个 model 文件

    所以就造了个轮子 不需要定义 model 类型的 curd 接口

    基于 gin 框架 只支持 mysql
    只需要改下 config/db.go 数据库配置文件就能直接 go run 起来 然后 curd 所有表了

    查一条:
    GET /tableName/get/:id
    查多条
    GET /tableName/list?page=1&size=10
    创建
    post /tableName/create (data={"name":"lalaal","age":"24",...})
    更新
    post /tableName/update/:id (data={"name":"lalaal","age":"24",...})
    删除
    get /tableName/delete/:id (支持 :id="1,2,3" 多个删除)

    /auth/getToken 来获取 token 不需要授权调用的话 也可以在验证 token 的时候直接返回 true

    https://github.com/niuoh/go_curd_api

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2352 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:12 · PVG 09:12 · LAX 18:12 · JFK 21:12
    ♥ Do have faith in what you're doing.