课程: Go Essentials: Concurrency, Connectivity, and High-Performance Apps

今天就学习课程吧!

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

Solution: Interfaces

Solution: Interfaces

(gentle music) - [Instructor] Here is my solution. Here is the capper struct. It's going to have only a single field, WTR, which is the underlying io.Writer. And then in order to implement the io.Writer interface, we implement the write method which gets a slice of bytes and return an integer for how many bytes are returned and a possible error. First to calculate the diff between the lowercase A, which has a higher value, and the uppercase A. Second, we are going to create a new byte slice. We don't want to change P. Then we iterate over every byte inside P, and if it's between lowercase A and lowercase Z, we reduce the diff to make it an uppercase letter and assign it to the output. And finally, we return the result of calling the underlying io.Writer write method. And now, we can use capper over Stdout and print out Hello there. So debug, start without debugging. And we are going to see Hello there all in…

内容