Official website Sunshinev.github. IO/Go-sword -ho…

What does she give you?

  1. You’re a code freak and don’t want tools to interfere too much with your business logic
  2. You want the generated pages to be customizable to achieve more functionality
  3. You want your code to be extremely simple to read and easy to customize
  4. You want to be able to quickly build an administrative back end, even if it’s just to visualize the data in your database
  5. You want one-click GENERATION of CRUDS with no complex operations
  6. You want to use the components of iView to build pages quickly

Then go-Sword will do it for you

According to the MySQL table structure, to create a complete management background interface, developers no longer need to manually create a PAGE with CRUD capability, just click the button to create a complete management background

The characteristics of

  1. One-click generation without writing a line of code
  2. Support to add, delete, edit, list, batch delete, paging, search
  3. The page is based on vue.js + iView
  4. A separate logical file is generated for each table, and developers can use Vue or iView to achieve richer pages

start

The installation

go get -u  github.com/sunshinev/go-sword
Copy the code

compile

go build
Copy the code

After the installation is complete, ensure that the Go-sword command is executable in the GOPATH/bin directory

Start the service

go-sword -db {db_database} -password {db_password} -user {db_uesr} -module {module_name}
Copy the code

For example, go-sword- db blog -password 123456 -user root-module go-sword-app

The above command is to connect database blog, user name root, password 12345, create project go-sword-app under the current directory of go-sword command

The startup success message is displayed

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
Copy the code

Parameters that

+---------------------------------------------------+ | | | Welcome to use Go-Sword | | | | Visualized tool | | Fastest to create CRUD background | | https://github.com/sunshinev/go-sword | | | +---------------------------------------------------+ Usage of go-sword: -db string MySQL database -host string MySQL host (default)"localhost"-module string New project module, the same as'module' in go.mod file.   (default "go-sword-app/"// Go-sword Default port for starting the service -p string Go-sword Server port (default)"8080")
  -password string
      MySQL password
  -port int
      MySQL port (default 3306)
  -user string
      MySQL user
Copy the code

Parameters: – the module

The -module argument represents the name of the project to be created and is the value of the module field in the new project go.mod file.

Pay attention to

The new project will be created in the module directory under the current directory where the Go-sword command is run

Start using the service

Start successful, server is running ...
Please request: http://localhost:8080
Copy the code

Click http://localhost:8080 to enter the visual tool page of the Web

Important: Describes the page functions

  1. First drop down select MySQL table, then clickPreviewButton to render the file you want to create
  2. Creating a new project file for the first time requires a clickselect allAll selected, the first creation contains the core files required to start the project
  3. Click on theGenerateButton, you can see the prompt file created successfully
  4. So far, our backend has been created successfully

Note:

  1. For the first time, select all files
  2. If you are creating a second admin page, you can select onlyselect diff & newButton, and then clickGeneratebutton
  3. Each time a new management page is generated, restart the newly created project

Start using the new project

Go to our newly created project directory

testTree - L 2. └ ─ ─ the go - sword - app ├ ─ ─ controller ├ ─ ─ the core ├ ─ ─. Mod ├ ─ ─. Sum ├ ─ ─ main. Go ├ ─ ─ model ├ ─ ─ the resource ├ ─ ─ the route └ ─ ─ the viewCopy the code

For example, we just ran the go-sword command in the test directory and created a project called test/ Go-sword -app

We went to the test/ Go-sword -app directory and started the project with the following command

Initialize the new project go mod init

Initialize the project with the Go mod. This module is the same as the project name.

go mod init {module}
Copy the code

Start the project

go run main.go
Copy the code

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
Copy the code

Manage background effects

  1. Backend error notification
  2. Add, delete, edit, list, batch delete, paging, search

Some of the problems

  1. Because golang’s map structure traverses out of order, the order of fields in some pages cannot be guaranteed to be the same as that in the database
  2. aboutmoduleThere may be a better solution
  3. It does not provide users with the ability to register and log in, which is not in line with the original intention. At the beginning, we wanted to do a more basic, fast page creation
  4. Generated project code, there is a lot of room for optimization

Page Function Display

The list of

delete

preview

The editor

Go-sword fork

If you want to customize, note that the Go-Sword project can be packaged as a single command, since all static files are packaged as well

Static file compression commands are as follows:

go-bindata -o assets/resource/dist.go -pkg resource resource/dist/...
Copy the code
go-bindata -o assets/stub/stub.go -pkg stub stub/...
Copy the code
go-bindata -o assets/view/view.go -pkg view view/...
Copy the code