课程: Practice It: Go REST API Server
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Check it: Move functions to a new module
(computer beeps) - Now that you've tried it, let's check it against my solution. I'll walk you through it. So first, we will create a source directory. If you didn't do that, that's fine. And under the source directory, we will create a backend directory. And in the backend directory, we will do go mod init example.com /backend and we see our go mod module was created. Now, we'll create our backend.go file, and in it, we are going to name the package backend, cause that's what we did. Then we're going to import some libraries. We have FMT log and net/http. Next we're going to add some functions. Now I'll add the handler function, helloWorld, which will take a response writer and the request. And as it did before, we will have it print out, "Hello World." Now we want to add the run function in order to start the server. And this time, we'll create it with the capital letter R, because it…