课程: Go Essentials: Concurrency, Connectivity, and High-Performance Apps
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Solution: Server kill - Go教程
课程: Go Essentials: Concurrency, Connectivity, and High-Performance Apps
Solution: Server kill
(upbeat music) - [Instructor] Here is my solution, function kill server. We first try to open the file. If there is an error we return error as is from the open. Otherwise we defer closing of the file. Then we have the pid variable and we're using Fscanf to try and read from the file into this integer. If there is an error, we use errors.Wrap to wrap the error with the bad process ID. And finally, we are going to print out that we're killing the server. After killing the server, we're going to remove the file. In this case, just to log the error but not return it because this is not an error if you can't remove the file. And finally, we return nil, signaling there is no error and the main state as is. So let's write the code, start without debugging. And we are going to say, there's open server.pid, no such file or directory. So let me add this file. So I'm going to create server.pid and I'm going to write seven in…