Go-sword
ใ็นๆ่ฎฟ้ฎไธญๆๆๆกฃ_cn_zhใ
Go-sword is a visual web management background generation tool based on Go language
The goal is to quickly create a CRUD visual background
According to the table structure of MySQL, create a complete management background interface, developers no longer need to manually create CRUD-capable pages
Just click the button to generate a complete management background
Features
- One-key generation without writing a line of code
- Support add, delete, edit, list, batch delete, paging, search
- The page is based on Vue.js + iView
- A separate logical file is generated for each data table, and developers can seek to use Vue or iView to implement more feature-rich pages
Start
Installation
go get -u github.com/sunshinev/go-sword
After the installation is complete, make sure that the go-sword
command is in the GOPATH/bin
directory, executable
Start the service
go-sword -db {db_database} -password {db_password} -user {db_uesr} -module {module_name}
For example: go-sword -db blog -password 123456 -user root -module go-sword-app
The above command is to connect to the database blog
, the username root
, the password 12345
, and create the project go-sword-app
in the current directory of the go-sword command
Tips for successful startup
Go-Sword will create new project named go-sword-app in current directory
[Server info]
Server port: 8080
Project module: go-sword-app
[db info]
MySQL host: localhost
MySQL port: 3306
MySQL user: root
MySQL password: 123456
Start successful, server is running ...
Please request: http://localhost: 8080
Parameter Description
+ ------------------------------------------------- -+
| |
| Welcome to use Go-Sword |
| |
| Visualized tool |
| Fastest to create CRUD background |
| https://github.com/sunshinev/go-sword |
| |
+ ------------------------------------------------- -+
Usage of go-sword:
//Database information to be connected
-db string
MySQL database
-host string
MySQL Host (default "localhost")
//Important: module parameters are explained separately
-module string
New project module, the same as 'module' in go.mod file. (Default "go-sword-app /")
//The default port where the go-sword service starts
-p string
Go-sword Server port (default "8080")
-password string
MySQL password
-port int
MySQL port (default 3306)
-user string
MySQL user
Parameters: -module
The -module
parameter is the name of the project to be created, and it is also the value of the module
field in the go.mod
file of the new project. Please make sure that this is consistent.
Note
The new project will directly create the module
directory under the current directory where the go-sword
command is run as the new project
Start using the service
Start successful, server is running ...
Please request: http://localhost: 8080
According to the prompt of service startup, directly click http://localhost: 8080
to enter the web visualization tool page
Important: Introduction to page functions
- First, select the MySQL table by drop-down, and then click the
Preview
button to render the file to be created - The first time you create a new project file you need to click
select all
to select all, the first time you create a core file that contains the necessary project start - Click the
Generate
button, you can see the prompt file successfully created - So far, our background has been successfully created
note:
- For the first time, all files need to be selected
- If you create a second management page, you can just select the
select diff & new
button and click theGenerate
button - Every time a new management interface is generated, please restart the newly created project
Start using a new project
Go to our newly created project directory
โ test tree -L 2
.
โโโ go-sword-app
โโโ controller
โโโ core
โโโ go.mod
โโโ go.sum
โโโ main.go
โโโ model
โโโ resource
โโโ route
โโโ view
For example, if we just run the go-sword
command in the test
directory, the created project is test/go-sword-app
We enter the test/go-sword-app
directory and start the project according to the following command
Initialize new project go mod init
Use go mod
to initialize the project, and the module
here is the same as the project name we mentioned earlier! !
go mod init {module}
###Startup project
go run main.go
Then you will see the following prompt, click http://localhost: 8082
to enter the background management interface
Enjoy your system ^ ^
Generated by Go-sword
https://github.com/sunshinev/go-sword
[Server info]
Server port: 8082
[db info]
MySQL host: localhost
MySQL port: 3306
MySQL user: root
MySQL password: 123456
Start successful, server is running ...
Please request: http://localhost: 8082
Manage background effects
- Back-end error notification
- Add, delete, edit, list, bulk delete, paging, search
some problems
- Because of the out-of-order traversal of golangโs map structure, the field order of some pages cannot be guaranteed to be consistent with the database field order
- There may be better solutions regarding the parameters of
module
- The ability to register and log in is not provided, which is not in line with the original intention. At the beginning, I wanted to do more basic things and quickly create pages
- The generated project code has a lot of room for optimization
Page function display
List
Delete
Preview
Edit
Go-sword fork
If you want to customize, then you need to note that the Go-sword project can be packaged into a single command to execute, because all static files are also packaged
The static file compression commands are as follows:
go-bindata -o assets/resource/dist.go -pkg resource resource/dist/...
go-bindata -o assets/stub/stub.go -pkg stub stub/...
go-bindata -o assets/view/view.go -pkg view view/...