1024Helper

module
v0.0.0-...-da9a27d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: GPL-3.0

README

1024Helper

1.使用gin+vue实现的博客程序,目前还是比较粗糙,在逐步完善中! Blog Admin: Blog Page: 2.带的ginhelper是用于gin框架快速开发的辅助工具,支持monorepo方式

ginhelper使用方法

  1. 安装ginhelper
>go get github.com/5bug/1024Helper/cmd/ginhelper
>ginhelper -h
Usage:
  ginhelper [command]

Available Commands:
  completion  generate the autocompletion script for the specified shell
  help        Help about any command
  new         create an app template
  update      update app api and service

Flags:
  -h, --help      help for ginhelper
  -v, --version   version for ginhelper

Use "ginhelper [command] --help" for more information about a command.
  1. 初始化工程
>mkdir ginhelper-demo
>cd ginhelper-demo
>ginhelper new

创建好的目录结构如下:

├── cmd
│   └── hello
│       └── main.go
├── go.mod
└── internal
    └── hello
        ├── api
        │   ├── api.go
        │   ├── handlers.go
        │   └── router.go
        ├── conf
        │   └── conf.go
        └── service
            ├── api.go
            └── service.go

  1. 定义api文件 这里api定义使用纯go代码实现,通过注解来定义路由、请求方法、是否需要认证,具体注解说明如下:
  • @Router: 路由定义 /xxx [请求方法]
  • @Auth: 是否需要认证 true/false

例如在internal/hello/api/目录下定义api文件user.go,内容如下:

package api

// UserRequest user request
// @Router /user [get]
// @Auth false
type UserRequest struct {
	ID int `json:"id" binding:"required"`
}

// UserReply user reply
type UserReply struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Sex   int    `json:"sex"`
	Email string `json:"email"`
}
  1. 根据API文件更新app服务
ginhelper update -a hello
  1. 在生成的internal/hello/service/xxx.go里实现自己的业务逻辑即可

RoadMap

完善中...

Directories

Path Synopsis
cmd
internal
blog/api
Code generated by generator.
Code generated by generator.
pkg
log

Jump to

Keyboard shortcuts

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