课程: Secure Coding in Go

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Secure project

Solution: Secure project

(upbeat music) - [Instructor] So here is my solution. I wrote a handler function called check authentication. These handler function check if you're under the prefix of /debug, it will look for the basic authentication and make sure it's valid. If it's not, it is going to return status of unauthorized. If you pass that meaning either the login is okay, or it's not on the /debug, it is going to call the DefaultServerMux with the original ResponseWriter and Request. In main(), we are going to convert the HandlerFunc to a handler, and we're going to pass it as the second parameter to ListenAndServe. Meaning every request is going to be directed through our checkAuth function. Let's have a look, So Run, Run Without Debugging and let's view the Debug Console and now we can check it out. So, curl -i https://localhost:8080/debug/vars and we get unauthorized. So let's pass the security information. So katie and the…

内容