Go 基础学习,简单爬虫与代理学习|青训营

106 阅读1分钟

这是我参与「第三届青训营 -后端场」笔记创作活动的的第1篇笔记

go的基础学习

//和java的不一样每个case 后面自带break 如果需要继续执行fallthrough,
会执行下一条没有fallthrough,也会执行默认的break
        switch a { 
	case 1:
		fmt.Println("one")
	case 2:
		fmt.Println("two")
		fallthrough
	case 3:
		fmt.Println("three")
	case 4, 5:
		fmt.Println("four or five")
	default:
		fmt.Println("other")
	}

go在函数中是值传递,虽然map和slice虽然是引用,但是原理利用对于地址的值传递。

type user struct {
	name     string
	password string
}
//下面两个是User 的类方法
func (u user) checkPassword(password string) bool {
	return u.password == password
}

func (u *user) resetPassword(password string) {
	u.password = password
}
//这个是普通方法
func checkPassword(u user, password string) bool {
	return u.password == password
}

go语言中打印的格式化

	s := "hello"
	n := 123
	p := point{1, 2}
	fmt.Println(s, n) // hello 123
	fmt.Println(p)    // {1 2}

	fmt.Printf("s=%v\n", s)  // s=hello
	fmt.Printf("n=%v\n", n)  // n=123
	fmt.Printf("p=%v\n", p)  // p={1 2}
	fmt.Printf("p=%+v\n", p) // p={x:1 y:2}
	fmt.Printf("p=%#v\n", p) // p=main.point{x:1, y:2}

	f := 3.141592653
	fmt.Println(f)          // 3.141592653
	fmt.Printf("%.2f\n", f) // 3.14

image.png go语言中对字符串的操作

image.png #小项目练手

猜字谜

下面框起来的3个比较重要对于终端输入的操作 也可以换成fmt.Scanf() image.png

在线词典抓包

学会了复制curl到curlconverter.com/#go 自动生成接口的爬取。 image.png json 格式转为 type struct oktools.net/json2go 并且利用go的携程,sync.Group 来控制主线程等待其他携程访问在结束,提高速度。Json的解码和编码

Socks5的代理实现

这个有点不太懂,后序继续研究。