day8方法

master
独孤伶俜 2022-12-14 22:42:18 +08:00
parent 2e765820cd
commit 62a52095d1
2 changed files with 24 additions and 2 deletions

View File

@ -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 {

View File

@ -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)
}