ktool

command module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 1 Imported by: 0

README

一款GIN的CLI工具

安装

go install github.com/hxoreyer/ktool@latest

创建应用

ktool init -n app

创建应用后会自动生成文件夹和mod等文件

cd app

创建路由

  1. 修改yaml文件的内容

    groups:
    - name: api/v1
      infos: 
        - method: POST
          path: /register
          function: Register
          file: user
        - method: GET
          path: /login
          function: Login
          file: user
    - name: api/v2
      infos: 
        - method: POST
          path: /register2
          function: Register2
          file: admin
        - method: GET
          path: /login2
          function: Login2
          file: admin
    
  2. 生成controller文件,默认为 config.yaml

    ktool router -p config.yaml
    

数据库

  1. 初始化数据库

    ktool mysql create -u hxoreyer -p password -a 123.11.22.321:1234 -d tableName
    
  2. 通过model文件生成service文件

    // 在models文件夹下创建user.go
    package models
    
    import (
    	"gorm.io/gorm"
    )
    
    type User struct {
    	gorm.Model
    	UserName string `gorm:"column:username"`
    	Password string `gorm:"column:password"`
    }
    
    #生成service文件(-n 为models里的文件名 不加后缀)
    ktool mysql new -n user
    

运行

go mod tidy
go run .
# 地址为localhost:5201

Documentation

Overview

Copyright © 2023 hxoreyer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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