今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Terminating HTTP handlers on error
- [Narrator] Plain bugs can cause security issues as well. Say you have an API to show some audit logs. Here is the audit handler, it gets the user and the password from the basic authentication. And if there's no authentication, or better authentication, it is emitting an error. Otherwise, we'll go load the audit logs, set the header and return json. So let's run this run, run without debugging. And let's view that the server is running. And now we can do curl -i https://localhost:8080/audits. And we're not going to give any login information. And we see that we get the unauthorized return value, and also here not authorized. But we also see the audits that are coming in. You need to remember that Go is not like other languages, it does not use exception handling HTTP error is not going to stop the current handler from executing, you need to do an explicit return. Let's copy the fix. And the only thing that has changed is now…