diff --git a/src/study/day7Function/DeferredFunc.go b/src/study/day7Function/DeferredFunc.go index 791863f..ca026e7 100644 --- a/src/study/day7Function/DeferredFunc.go +++ b/src/study/day7Function/DeferredFunc.go @@ -24,7 +24,7 @@ func title(url string) error { } // 直到包含defer的函数执行完毕之后,defer的这条语句才会执行 defer resp.Body.Close() - // Check Content-Type is HTML (e.g., "text/html;charset=utf-8"). + // Check Content-Type is Html (e.g., "text/html;charset=utf-8"). ct := resp.Header.Get("Content-Type") if ct != "text/html" && !strings.HasPrefix(ct, "text/html;") { return fmt.Errorf("%s has type %s, not text/html", url, ct) @@ -32,7 +32,7 @@ func title(url string) error { doc, err := html.Parse(resp.Body) if err != nil { - return fmt.Errorf("parsing %s as HTML: %v", url, err) + return fmt.Errorf("parsing %s as Html: %v", url, err) } visitNode := func(n *html.Node) { if n.Type == html.ElementNode && n.Data == "title" && n.FirstChild != nil { diff --git a/src/study/day9Interface/main.go b/src/study/day9Interface/main.go new file mode 100644 index 0000000..836fe28 --- /dev/null +++ b/src/study/day9Interface/main.go @@ -0,0 +1,22 @@ +package main + +import "fmt" + +type www interface { + Write() +} +type ByteCounter int + +func (c *ByteCounter) Write(p []byte) (int, error) { + *c += ByteCounter(len(p)) + return len(p), nil +} + +func main() { + var c ByteCounter + c.Write([]byte("hello")) + fmt.Println(c) + name := "dugulp" + fmt.Fprintf(&c, "Hello, %s", name) + fmt.Println(c) +}