Article Directory
Implement a simple user system
Now that the code is written, you will find that we already have a short program (only 60 lines!), but can implement a basic background interface and interact with the database! This is really exciting! Then keep this enthusiasm, let's implement a basic user system!
Before that, we have to tidy up our code (although it only has 60 lines):
3.1 Start to organize our code structure
Our main.go
years now includes several parts: a statement routing, establish a database connection, as well as a handler, but these things are put together will feel a bit chaotic. So let's build a good catalog!
The rebuilt directory structure is as follows:
├── handler
│ ├── handler.go
│ ├── login
│ └── register
│ └── register.go
├── model
│ ├── init.go
│ └── user.go
├── router
│ └── router.go
└── main.go
Then we explain the role of each part:
- handler