课程: Practice It: Go REST API Server
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Creating handlers: GET
- [Instructor] Now that we've discussed routers, let's put it to good use. We will separate product and order handlers into their own files for better code layout and use the router to redirect the request to the correct function to handle it. The first type of handler will talk about our get handlers. Get to the most commonly used requests. And the endpoints are similar to slash products or slash products slash three. In our backend directory, I'm going to create the product file. So I'll go to backend, plus, product.go. And in the file we want to make it package backend or if you used a different package name, use that package name. Next, we'll do some imports. We'll need the database, some logs, and we'll need the SQLite. Then I'll create the product struct. So we'll have type product struct. Now is a good time to bring up returning results in a JSON format, which is designed specifically for data exchange…