课程: Practice It: Go REST API Server
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Hello World
- [Instructor] Now that we have set up the environment let's get right to creating an API server. We create the main.go file. So we come over to the left hand side we hit the new file, we name it main.go. So the first line in the file will be package main. Next, we want to import any go internal go packages or any external third party packages. But to start, we only need FMT, log, and net/http which are all internal go packages. Then we'll create a hello world function, that will take as parameters, the response writer, W, and the request. And then we'll add the curly brackets. Now since it's a simple call, we won't need to check the request. We're just going to send back hello world to the response writer W. So to do that we will just do FMT.f, print F, send it to W, and the words, Hello world. Now in order to run this we need a main function. So we have function, main, no parameters and the curly brackets. And in the…