241113.学习日志——[CSDIY] [ByteDance] 后端训练营 [00]

CSDIY:这是一个非科班学生的努力之路,从今天开始这个系列会长期更新,(最好做到日更),我会慢慢把自己目前对CS的努力逐一上传,帮助那些和我一样有着梦想的玩家取得胜利!!!
第一弹:Cpp零基础学习【30 DAYS 从0到1】
第二弹:Go开发入门【字节后端青训营】

ByteDance青训营 后端方向 00 Go 语言入门
Go 语言快速上手

1.2 什么是 Go 语言

  1. 高性能、高并发
  2. 语法简单、学习曲线平缓(入门到开发项目只需要一周时间)
  3. 丰富的标准库(类似 Cpp 有很多标准库,减少第三方库的使用)
  4. 完善的的工具链(代码补充、代码管理等)
  5. 静态链接(只需要一个可执行文件即可,部署方便)
  6. 快速编译
  7. 跨平台(跨Window/Linux/Unix/Mac)
  8. 垃圾回收(自动内存分配和释放)

1.2 哪些公司在用

  • ByteDance
  • Google
  • Tencent
  • facebook
  • DiDi
  • Bilibili
  • Meituan

1.3 为什么 ByteDance 使用 Go

  1. C++不适合在线Web
  2. 性能优秀、部署简单、学习成本低
  3. 内部 RPC 和 HTTP 框架的推广

2.1 开发环境

  • Golang

2.2 基础语法

Hello World
package mainimport "fmt"func main() {fmt.Println("Hello, World!")
}
变量
package mainimport ("fmt""math"
)func main() {var a = "initial"var b, c int = 1, 2var d = truevar e float64f := float32(e)g := a + "foo"fmt.Println(a, b, c, d, e, f) // initial 1 2 true 0 0fmt.Println(g)                // initialappleconst s string = "constant"const h = 500000000const i = 3e20 / hfmt.Println(s, h, i, math.Sin(h), math.Sin(i))
}
if else
package mainimport "fmt"func main() {if 7%2 == 0 {fmt.Println("7 is even")} else {fmt.Println("7 is odd")}if 8%4 == 0 {fmt.Println("8 is divisible by 4")}if num := 9; num < 0 {fmt.Println(num, "is negative")} else if num < 10 {fmt.Println(num, "has 1 digit")} else {fmt.Println(num, "has multiple digits")}
}
循环
package mainimport "fmt"func main() {i := 1for {fmt.Println("loop")break}for j := 7; j < 9; j++ {fmt.Println(j)}for n := 0; n < 5; n++ {if n%2 == 0 {continue}fmt.Println(n)}for i <= 3 {fmt.Println(i)i = i + 1}
}
switch

自动执行break

package mainimport ("fmt""time"
)func main() {a := 2switch a {case 1:fmt.Println("one")case 2:fmt.Println("two")case 3:fmt.Println("three")case 4, 5:fmt.Println("four or five")default:fmt.Println("other")}t := time.Now()switch {case t.Hour() < 12:fmt.Println("It's before noon")default:fmt.Println("It's after noon")}
}
数组
package mainimport "fmt"func main() {var a [5]inta[4] = 100fmt.Println("get:", a[2])fmt.Println("len:", len(a))b := [5]int{1, 2, 3, 4, 5}fmt.Println(b)var twoD [2][3]intfor i := 0; i < 2; i++ {for j := 0; j < 3; j++ {twoD[i][j] = i + j}}fmt.Println("2d: ", twoD)
}
切片
package mainimport "fmt"func main() {s := make([]string, 3)	// 创建切片 Ss[0] = "a"s[1] = "b"s[2] = "c"fmt.Println("get:", s[2])   // cfmt.Println("len:", len(s)) // 3s = append(s, "d")s = append(s, "e", "f")fmt.Println(s) // [a b c d e f]c := make([]string, len(s))copy(c, s)fmt.Println(c) // [a b c d e f]fmt.Println(s[2:5]) // [c d e]	从 2 到 5(不含)fmt.Println(s[:5])  // [a b c d e]fmt.Println(s[2:])  // [c d e f]good := []string{"g", "o", "o", "d"}fmt.Println(good) // [g o o d]
}
map
package mainimport "fmt"func main() {m := make(map[string]int)m["one"] = 1m["two"] = 2fmt.Println(m)           // map[one:1 two:2]fmt.Println(len(m))      // 2fmt.Println(m["one"])    // 1fmt.Println(m["unknow"]) // 0r, ok := m["unknow"]fmt.Println(r, ok) // 0 falsedelete(m, "one")m2 := map[string]int{"one": 1, "two": 2}var m3 = map[string]int{"one": 1, "two": 2}fmt.Println(m2, m3)
}
range
package mainimport "fmt"func main() {nums := []int{2, 3, 4}sum := 0for i, num := range nums {sum += numif num == 2 {fmt.Println("index:", i, "num:", num) // index: 0 num: 2}}fmt.Println(sum) // 9m := map[string]string{"a": "A", "b": "B"}for k, v := range m {fmt.Println(k, v) // b 8; a A}for k := range m {fmt.Println("key", k) // key a; key b}
}
函数

函数会有两个结果(一个是函数返回值,一个是错误结果)

package mainimport "fmt"func add(a int, b int) int {return a + b
}func add2(a, b int) int {return a + b
}func exists(m map[string]string, k string) (v string, ok bool) {v, ok = m[k]return v, ok	// 两个返回值 ok 表示错误结果
}func main() {res := add(1, 2)fmt.Println(res) // 3v, ok := exists(map[string]string{"a": "A"}, "a")fmt.Println(v, ok) // A True
}
指针
package mainimport "fmt"// 实际上无效, 因为传入的是copy的参数
func add2(n int) {n += 2
}func add2ptr(n *int) {*n += 2
}func main() {n := 5add2(n)fmt.Println(n) // 5add2ptr(&n)fmt.Println(n) // 7
}
结构体
package mainimport "fmt"type user struct {name     stringpassword string
}func main() {// 初始化结构体变量a := user{name: "wang", password: "1024"}b := user{"wang", "1024"}c := user{name: "wang"}c.password = "1024"var d user// 像 C 语言一样初始化、赋值操作d.name = "wang"d.password = "1024"fmt.Println(a, b, c, d)                 // {wang 1024} {wang 1024} {wang 1024} {wang 1024}fmt.Println(checkPassword(a, "haha"))   // falsefmt.Println(checkPassword2(&a, "haha")) // false
}func checkPassword(u user, password string) bool {return u.password == password
}func checkPassword2(u *user, password string) bool {return u.password == password
}
结构体方法
package mainimport "fmt"type user struct {name     stringpassword string
}// 结构体函数
func (u user) checkPassword(password string) bool {return u.password == password
}func (u *user) resetPassword(password string) {u.password = password
}func main() {a := user{name: "wang", password: "1024"}a.resetPassword("2048")fmt.Println(a.checkPassword("2048")) // true
}
错误处理

对于可能发生错误的函数,可以返回一个错误信息,结合 if else 提高性能

package mainimport ("errors""fmt"
)type user struct {name     stringpassword string
}func findUser(users []user, name string) (v *user, err error) {for _, u := range users {if u.name == name {return &u, nil}}return nil, errors.New("not found")
}func main() {u, err := findUser([]user{{"wang", "1024"}}, "wang")if err != nil {fmt.Println(err)return}fmt.Println(u.name) // wangif u, err := findUser([]user{{"wang", "1024"}}, "li"); err != nil {fmt.Println(err) // not foundreturn} else {fmt.Println(u.name)}
}
字符串处理

go 语言字符串可以直接相加结合

package mainimport ("fmt""strings"
)func main() {a := "hello"fmt.Println(strings.Contains(a, "ll"))                // truefmt.Println(strings.Count(a, "l"))                    // 2fmt.Println(strings.HasPrefix(a, "he"))               // truefmt.Println(strings.HasSuffix(a, "llo"))              // truefmt.Println(strings.Index(a, "ll"))                   // 2fmt.Println(strings.Join([]string{"he", "llo"}, "-")) // he-llofmt.Println(strings.Repeat(a, 2))                     // hellohellofmt.Println(strings.Replace(a, "e", "E", -1))         // hEllofmt.Println(strings.Split("a-b-c", "-"))              // [a b c]fmt.Println(strings.ToLower(a))                       // hellofmt.Println(strings.ToUpper(a))                       // HELLOfmt.Println(len(a))                                   // 5b := "你好"fmt.Println(len(b)) // 6
}
字符串格式化

可以用 %v 通用表示:字符串,数字,结构体值

%+v打印:结构体字段名字、值

%#v打印:结构体名称、字段名字、值

也可以用 %.2f 打印小数点

package mainimport "fmt"type point struct {x, y int
}func main() {s := "hello"n := 123p := point{1, 2}fmt.Println(s, n) // hello 123fmt.Println(p)    // {1 2}fmt.Printf("s=%v\n", s)  // s=hellofmt.Printf("n=%v\n", n)  // n=123fmt.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.141592653fmt.Println(f)          // 3.141592653fmt.Printf("%.2f\n", f) // 3.14
}
JSON 处理
package mainimport ("encoding/json""fmt"
)type userInfo struct {Name  stringAge   int `json:"age"`Hobby []string
}func main() {a := userInfo{Name: "wang", Age: 18, Hobby: []string{"Golang", "TypeScript"}}buf, err := json.Marshal(a)if err != nil {panic(err)}fmt.Println(buf)         // [123 34 78 97...]fmt.Println(string(buf)) // {"Name":"wang","age":18,"Hobby":["Golang","TypeScript"]}buf, err = json.MarshalIndent(a, "", "\t")if err != nil {panic(err)}fmt.Println(string(buf))var b userInfoerr = json.Unmarshal(buf, &b)if err != nil {panic(err)}fmt.Printf("%#v\n", b) // main.userInfo{Name:"wang", Age:18, Hobby:[]string{"Golang", "TypeScript"}}
}
时间处理
package mainimport ("fmt""time"
)func main() {now := time.Now()fmt.Println(now) // 2022-03-27 18:04:59.433297 +0800 CST m=+0.000087933t := time.Date(2022, 3, 27, 1, 25, 36, 0, time.UTC)t2 := time.Date(2022, 3, 27, 2, 30, 36, 0, time.UTC)fmt.Println(t)                                                  // 2022-03-27 01:25:36 +0000 UTCfmt.Println(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute()) // 2022 March 27 1 25fmt.Println(t.Format("2006-01-02 15:04:05"))                    // 2022-03-27 01:25:36// 可以计算两个时间之间的时间段diff := t2.Sub(t)fmt.Println(diff)                           // 1h5m0sfmt.Println(diff.Minutes(), diff.Seconds()) // 65 3900// 可以将字符串解析为时间戳t3, err := time.Parse("2006-01-02 15:04:05", "2022-03-27 01:25:36")if err != nil {panic(err)}fmt.Println(t3 == t)    // truefmt.Println(now.Unix()) // 1648738080
}
数字解析

数字和字符串互相转化

package mainimport ("fmt""strconv"
)func main() {f, _ := strconv.ParseFloat("1.234", 64)fmt.Println(f) // 1.234n, _ := strconv.ParseInt("111", 10, 64)fmt.Println(n) // 111n, _ = strconv.ParseInt("0x1000", 0, 64)fmt.Println(n) // 4096n2, _ := strconv.Atoi("123")fmt.Println(n2) // 123n2, err := strconv.Atoi("AAA")fmt.Println(n2, err) // 0 strconv.Atoi: parsing "AAA": invalid syntax
}
进程信息
package mainimport ("fmt""os""os/exec"
)func main() {// go run example/20-env/main.go a b c dfmt.Println(os.Args)           // [/var/folders/8p/n34xxfnx38dg8bv_x8l62t_m0000gn/T/go-build3406981276/b001/exe/main a b c d]// 环境变量fmt.Println(os.Getenv("PATH")) // /usr/local/go/bin...fmt.Println(os.Setenv("AA", "BB"))// 输入输出buf, err := exec.Command("grep", "127.0.0.1", "/etc/hosts").CombinedOutput()if err != nil {panic(err)}fmt.Println(string(buf)) // 127.0.0.1       localhost
}

3.1 猜谜游戏

3.1.1 生成随机数
package mainimport ("fmt""math/rand"
)func main() {maxNum := 100// 使用 rand 包来生成随机数secretNumber := rand.Intn(maxNum)fmt.Println("The secret number is ", secretNumber)
}

输出发现每次产生的随机数都会生成相同的数字,需要加上随机数种子

3.1.2 生成随机数 V2
package mainimport ("fmt""math/rand""time"
)func main() {maxNum := 100// 添加时间随机数种子,达到随机目的rand.Seed(time.Now().UnixNano())secretNumber := rand.Intn(maxNum)fmt.Println("The secret number is ", secretNumber)
}
3.1.3 读取用户输入
package mainimport ("bufio"	// 读取输入输出的包"fmt""math/rand""os""strconv""strings""time"
)func main() {maxNum := 100rand.Seed(time.Now().UnixNano())secretNumber := rand.Intn(maxNum)fmt.Println("The secret number is ", secretNumber)fmt.Println("Please input your guess")// 读取用户一行输入reader := bufio.NewReader(os.Stdin)input, err := reader.ReadString('\n')if err != nil {fmt.Println("An error occured while reading input. Please try again", err)return}// 去掉换行符input = strings.Trim(input, "\r\n")// 字符串转换为数字:Atoiguess, err := strconv.Atoi(input)// 转换失败的时候 输出错误消息if err != nil {fmt.Println("Invalid input. Please enter an integer value")return}fmt.Println("You guess is", guess)
}
3.1.4 实现判断逻辑
package mainimport ("bufio""fmt""math/rand""os""strconv""strings""time"
)func main() {maxNum := 100rand.Seed(time.Now().UnixNano())secretNumber := rand.Intn(maxNum)fmt.Println("The secret number is ", secretNumber)fmt.Println("Please input your guess")reader := bufio.NewReader(os.Stdin)input, err := reader.ReadString('\n')if err != nil {fmt.Println("An error occured while reading input. Please try again", err)return}input = strings.Trim(input, "\r\n")guess, err := strconv.Atoi(input)if err != nil {fmt.Println("Invalid input. Please enter an integer value")return}fmt.Println("You guess is", guess)if guess > secretNumber {fmt.Println("Your guess is bigger than the secret number. Please try again")} else if guess < secretNumber {fmt.Println("Your guess is smaller than the secret number. Please try again")} else {fmt.Println("Correct, you Legend!")}
}

添加了是否判断正确的逻辑,但是用户只能输入一次,此时需要考虑添加循环,实现用户多次输入。

3.1.5 实现游戏循环
package mainimport ("bufio""fmt""math/rand""os""strconv""strings""time"
)func main() {maxNum := 100rand.Seed(time.Now().UnixNano())secretNumber := rand.Intn(maxNum)// 屏蔽随机数结果// fmt.Println("The secret number is ", secretNumber)fmt.Println("Please input your guess")fmt.scanf("&num")reader := bufio.NewReader(os.Stdin)for {input, err := reader.ReadString('\n')if err != nil {fmt.Println("An error occured while reading input. Please try again", err)// 出错的时候继续下一次循环continue}input = strings.Trim(input, "\r\n")guess, err := strconv.Atoi(input)if err != nil {fmt.Println("Invalid input. Please enter an integer value")// 出错的时候继续下一次循环continue}fmt.Println("You guess is", guess)if guess > secretNumber {fmt.Println("Your guess is bigger than the secret number. Please try again")} else if guess < secretNumber {fmt.Println("Your guess is smaller than the secret number. Please try again")} else {fmt.Println("Correct, you Legend!")// 成功时 break 跳出循环break}}
}

3.2 在线词典

调用第三方 API 进行在线查询

3.2.1 抓包

调用 API : https://fanyi.caiyunapp.com/#/

curl 'https://api.interpreter.caiyunai.com/v1/dict' \-H 'accept: application/json, text/plain, */*' \-H 'accept-language: zh' \-H 'app-name: xiaoyi' \-H 'authorization: Bearer' \-H 'content-type: application/json;charset=UTF-8' \-H 'device-id: d7a3b39cabbf9091dd99920e3812ff88' \-H 'origin: https://fanyi.caiyunapp.com' \-H 'os-type: web' \-H 'os-version;' \-H 'priority: u=1, i' \-H 'referer: https://fanyi.caiyunapp.com/' \-H 'sec-ch-ua: "Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"' \-H 'sec-ch-ua-mobile: ?0' \-H 'sec-ch-ua-platform: "Windows"' \-H 'sec-fetch-dest: empty' \-H 'sec-fetch-mode: cors' \-H 'sec-fetch-site: cross-site' \-H 'sec-gpc: 1' \-H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36' \-H 'x-authorization: token:qgemv4jr1y38jyq6vhvi' \--data-raw '{"trans_type":"en2zh","source":"hello"}'
3.2.2 代码生成

将上面的代码转化为 go 语言代码

代码生成:https://curlconverter.com/go/

package mainimport ("fmt""io""log""net/http""strings"
)func main() {client := &http.Client{}var data = strings.NewReader(`{"trans_type":"en2zh","source":"hello"}`)// 创建请求:POST请求头,data流req, err := http.NewRequest("POST", "https://api.interpreter.caiyunai.com/v1/dict", data)if err != nil {log.Fatal(err)}// 设置请求头req.Header.Set("accept", "application/json, text/plain, */*")req.Header.Set("accept-language", "zh")req.Header.Set("app-name", "xiaoyi")req.Header.Set("authorization", "Bearer")req.Header.Set("content-type", "application/json;charset=UTF-8")req.Header.Set("device-id", "d7a3b39cabbf9091dd99920e3812ff88")req.Header.Set("origin", "https://fanyi.caiyunapp.com")req.Header.Set("os-type", "web")req.Header.Set("os-version", "")req.Header.Set("priority", "u=1, i")req.Header.Set("referer", "https://fanyi.caiyunapp.com/")req.Header.Set("sec-ch-ua", `"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"`)req.Header.Set("sec-ch-ua-mobile", "?0")req.Header.Set("sec-ch-ua-platform", `"Windows"`)req.Header.Set("sec-fetch-dest", "empty")req.Header.Set("sec-fetch-mode", "cors")req.Header.Set("sec-fetch-site", "cross-site")req.Header.Set("sec-gpc", "1")req.Header.Set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")req.Header.Set("x-authorization", "token:qgemv4jr1y38jyq6vhvi")// 发起请求:返回resp和errresp, err := client.Do(req)// 如果产生err会直接退出进程if err != nil {log.Fatal(err)}// 收到相应后立马关闭defer resp.Body.Close()// 读取响应bodyText, err := io.ReadAll(resp.Body)// 响应err也会退出进程if err != nil {log.Fatal(err)}fmt.Printf("%s\n", bodyText)
}
3.2.3 生成 request body

添加 JSON 字段 和 3.2.2 输出结果应当相同

package mainimport ("bytes""encoding/json""fmt""io""log""net/http"
)type DictRequest struct {TransType string `json:"trans_type"`Source    string `json:"source"`UserID    string `json:"user_id"`
}func main() {client := &http.Client{}// 初始化 request 结构变量request := DictRequest{TransType: "en2zh", Source: "hello"}buf, err := json.Marshal(request)if err != nil {log.Fatal(err)}// 转化为 datavar data = bytes.NewReader(buf)// 创建请求:POST请求头,data流req, err := http.NewRequest("POST", "https://api.interpreter.caiyunai.com/v1/dict", data)if err != nil {log.Fatal(err)}// 设置请求头req.Header.Set("accept", "application/json, text/plain, */*")req.Header.Set("accept-language", "zh")req.Header.Set("app-name", "xiaoyi")req.Header.Set("authorization", "Bearer")req.Header.Set("content-type", "application/json;charset=UTF-8")req.Header.Set("device-id", "d7a3b39cabbf9091dd99920e3812ff88")req.Header.Set("origin", "https://fanyi.caiyunapp.com")req.Header.Set("os-type", "web")req.Header.Set("os-version", "")req.Header.Set("priority", "u=1, i")req.Header.Set("referer", "https://fanyi.caiyunapp.com/")req.Header.Set("sec-ch-ua", `"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"`)req.Header.Set("sec-ch-ua-mobile", "?0")req.Header.Set("sec-ch-ua-platform", `"Windows"`)req.Header.Set("sec-fetch-dest", "empty")req.Header.Set("sec-fetch-mode", "cors")req.Header.Set("sec-fetch-site", "cross-site")req.Header.Set("sec-gpc", "1")req.Header.Set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")req.Header.Set("x-authorization", "token:qgemv4jr1y38jyq6vhvi")// 发起请求:返回resp和errresp, err := client.Do(req)// 如果产生err会直接退出进程if err != nil {log.Fatal(err)}// 收到相应后立马关闭defer resp.Body.Close()// 读取响应bodyText, err := io.ReadAll(resp.Body)// 响应err也会退出进程if err != nil {log.Fatal(err)}fmt.Printf("%s\n", bodyText)
}
3.2.4 解析 response body

代码生成:https://oktools.iokde.com/json2go

package mainimport ("bytes""encoding/json""fmt""io""log""net/http"
)type DictRequest struct {TransType string `json:"trans_type"`Source    string `json:"source"`UserID    string `json:"user_id"`
}type DictResponse struct {Rc   int `json:"rc"`Wiki struct {KnownInLaguages int `json:"known_in_laguages"`Description     struct {Source string      `json:"source"`Target interface{} `json:"target"`} `json:"description"`ID   string `json:"id"`Item struct {Source string `json:"source"`Target string `json:"target"`} `json:"item"`ImageURL  string `json:"image_url"`IsSubject string `json:"is_subject"`Sitelink  string `json:"sitelink"`} `json:"wiki"`Dictionary struct {Prons struct {EnUs string `json:"en-us"`En   string `json:"en"`} `json:"prons"`Explanations []string      `json:"explanations"`Synonym      []string      `json:"synonym"`Antonym      []string      `json:"antonym"`WqxExample   [][]string    `json:"wqx_example"`Entry        string        `json:"entry"`Type         string        `json:"type"`Related      []interface{} `json:"related"`Source       string        `json:"source"`} `json:"dictionary"`
}func main() {client := &http.Client{}// 初始化 request 结构变量request := DictRequest{TransType: "en2zh", Source: "hello"}buf, err := json.Marshal(request)if err != nil {log.Fatal(err)}// 转化为 datavar data = bytes.NewReader(buf)// 创建请求:POST请求头,data流req, err := http.NewRequest("POST", "https://api.interpreter.caiyunai.com/v1/dict", data)if err != nil {log.Fatal(err)}// 设置请求头req.Header.Set("accept", "application/json, text/plain, */*")req.Header.Set("accept-language", "zh")req.Header.Set("app-name", "xiaoyi")req.Header.Set("authorization", "Bearer")req.Header.Set("content-type", "application/json;charset=UTF-8")req.Header.Set("device-id", "d7a3b39cabbf9091dd99920e3812ff88")req.Header.Set("origin", "https://fanyi.caiyunapp.com")req.Header.Set("os-type", "web")req.Header.Set("os-version", "")req.Header.Set("priority", "u=1, i")req.Header.Set("referer", "https://fanyi.caiyunapp.com/")req.Header.Set("sec-ch-ua", `"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"`)req.Header.Set("sec-ch-ua-mobile", "?0")req.Header.Set("sec-ch-ua-platform", `"Windows"`)req.Header.Set("sec-fetch-dest", "empty")req.Header.Set("sec-fetch-mode", "cors")req.Header.Set("sec-fetch-site", "cross-site")req.Header.Set("sec-gpc", "1")req.Header.Set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")req.Header.Set("x-authorization", "token:qgemv4jr1y38jyq6vhvi")// 发起请求:返回resp和errresp, err := client.Do(req)// 如果产生err会直接退出进程if err != nil {log.Fatal(err)}// 收到相应后立马关闭defer resp.Body.Close()// 读取响应bodyText, err := io.ReadAll(resp.Body)// 响应err也会退出进程if err != nil {log.Fatal(err)}// fmt.Printf("%s\n", bodyText)var dictResponse DictResponseerr = json.Unmarshal(bodyText, &dictResponse)if err != nil {log.Fatal(err)}fmt.Printf("%#v\n", dictResponse)
}
3.2.5 打印结果/完善代码
// 简易单词在线查询
// 请在新建终端中进行操作
// 输入参数:1:go run "d:\VSCode\Go\Code\Helloworld.go" 2:单词 空格间隔
// 输入样例:go run "d:\VSCode\Go\Code\Helloworld.go" hello
// 输出样例:hello UK: [ˈheˈləu] US: [həˈlo]
//			int.喂;哈罗
//			n.引人注意的呼声
//			v.向人呼(喂)package mainimport ("bytes""encoding/json""fmt""io""log""net/http""os"
)type DictRequest struct {TransType string `json:"trans_type"`Source    string `json:"source"`UserID    string `json:"user_id"`
}type DictResponse struct {Rc   int `json:"rc"`Wiki struct {KnownInLaguages int `json:"known_in_laguages"`Description     struct {Source string      `json:"source"`Target interface{} `json:"target"`} `json:"description"`ID   string `json:"id"`Item struct {Source string `json:"source"`Target string `json:"target"`} `json:"item"`ImageURL  string `json:"image_url"`IsSubject string `json:"is_subject"`Sitelink  string `json:"sitelink"`} `json:"wiki"`Dictionary struct {Prons struct {EnUs string `json:"en-us"`En   string `json:"en"`} `json:"prons"`Explanations []string      `json:"explanations"`Synonym      []string      `json:"synonym"`Antonym      []string      `json:"antonym"`WqxExample   [][]string    `json:"wqx_example"`Entry        string        `json:"entry"`Type         string        `json:"type"`Related      []interface{} `json:"related"`Source       string        `json:"source"`} `json:"dictionary"`
}func query(word string) {client := &http.Client{}// 初始化 request 结构变量request := DictRequest{TransType: "en2zh", Source: word}buf, err := json.Marshal(request)if err != nil {log.Fatal(err)}// 转化为 datavar data = bytes.NewReader(buf)// 创建请求:POST请求头,data流req, err := http.NewRequest("POST", "https://api.interpreter.caiyunai.com/v1/dict", data)if err != nil {log.Fatal(err)}// 设置请求头req.Header.Set("accept", "application/json, text/plain, */*")req.Header.Set("accept-language", "zh")req.Header.Set("app-name", "xiaoyi")req.Header.Set("authorization", "Bearer")req.Header.Set("content-type", "application/json;charset=UTF-8")req.Header.Set("device-id", "d7a3b39cabbf9091dd99920e3812ff88")req.Header.Set("origin", "https://fanyi.caiyunapp.com")req.Header.Set("os-type", "web")req.Header.Set("os-version", "")req.Header.Set("priority", "u=1, i")req.Header.Set("referer", "https://fanyi.caiyunapp.com/")req.Header.Set("sec-ch-ua", `"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"`)req.Header.Set("sec-ch-ua-mobile", "?0")req.Header.Set("sec-ch-ua-platform", `"Windows"`)req.Header.Set("sec-fetch-dest", "empty")req.Header.Set("sec-fetch-mode", "cors")req.Header.Set("sec-fetch-site", "cross-site")req.Header.Set("sec-gpc", "1")req.Header.Set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")req.Header.Set("x-authorization", "token:qgemv4jr1y38jyq6vhvi")// 发起请求:返回resp和errresp, err := client.Do(req)// 如果产生err会直接退出进程if err != nil {log.Fatal(err)}// 收到相应后立马关闭defer resp.Body.Close()// 读取响应bodyText, err := io.ReadAll(resp.Body)// 响应err也会退出进程if err != nil {log.Fatal(err)}// 防御性编程,有可能是404等出错码if resp.StatusCode != 200 {log.Fatal("bad StatusCode:", resp.StatusCode, string(bodyText))}// fmt.Printf("%s\n", bodyText)var dictResponse DictResponseerr = json.Unmarshal(bodyText, &dictResponse)if err != nil {log.Fatal(err)}// fmt.Printf("%#v\n", dictResponse)fmt.Println(word, "UK:", dictResponse.Dictionary.Prons.En, "US:", dictResponse.Dictionary.Prons.EnUs)for _, item := range dictResponse.Dictionary.Explanations {fmt.Println(item)}
}// 主函数
func main() {// 输入参数:1:go run "d:\VSCode\Go\Code\Helloworld.go" 2:单词 空格间隔// 输入样例:go run "d:\VSCode\Go\Code\Helloworld.go" hello// 若样例不足两个,返回错误,退出进程if len(os.Args) != 2 {fmt.Fprintf(os.Stderr, `usage: simpleDict WORD
example: simpleDict hello`)os.Exit(1)}word := os.Args[1]query(word)
}

3.3 SOCKS5 代理服务器

某些企业为了网络安全会拥有自己的代理服务器

原理:

Client Socks5 Server Host Socks Principle 1.协商阶段 1.1.通过协商 2.发送请求 2.1.建立TCP链接 2.2.返回响应 2.3.返回状态 3.发送数据 3.1.relay数据 3.2.响应结果 3.3.响应结果 Client Socks5 Server Host
3.3.1 TCP echo server
package mainimport ("bufio""log""net"
)func main() {server, err := net.Listen("tcp", "127.0.0.1:1080")if err != nil {panic(err)}for {client, err := server.Accept()if err != nil {log.Printf("Accept failed %v", err)continue}// 启动一个子线程进行开销go process(client)}
}func process(conn net.Conn) {// 关闭链接,生命周期相等defer conn.Close()// 创建带缓冲流reader := bufio.NewReader(conn)// for死循环for {b, err := reader.ReadByte()if err != nil {break}// 写入一个字节_, err = conn.Write([]byte{b})if err != nil {break}}
}
3.3.2 auth
package mainimport ("bufio""fmt""io""log""net"
)const socks5Ver = 0x05
const cmdBind = 0x01
const atypeIPV4 = 0x01
const atypeHOST = 0x03
const atypeIPV6 = 0x04func main() {server, err := net.Listen("tcp", "127.0.0.1:1080")if err != nil {panic(err)}for {client, err := server.Accept()if err != nil {log.Printf("Accept failed %v", err)continue}go process(client)}
}func process(conn net.Conn) {defer conn.Close()reader := bufio.NewReader(conn)err := auth(reader, conn)if err != nil {log.Printf("client %v auth failed:%v", conn.RemoteAddr(), err)return}log.Println("auth success")
}func auth(reader *bufio.Reader, conn net.Conn) (err error) {// +----+----------+----------+// |VER | NMETHODS | METHODS  |// +----+----------+----------+// | 1  |    1     | 1 to 255 |// +----+----------+----------+// VER: 协议版本,socks5为0x05// NMETHODS: 支持认证的方法数量// METHODS: 对应NMETHODS,NMETHODS的值为多少,METHODS就有多少个字节。RFC预定义了一些值的含义,内容如下:// X’00’ NO AUTHENTICATION REQUIRED// X’02’ USERNAME/PASSWORDver, err := reader.ReadByte()if err != nil {return fmt.Errorf("read ver failed:%w", err)}if ver != socks5Ver {return fmt.Errorf("not supported ver:%v", ver)}methodSize, err := reader.ReadByte()if err != nil {return fmt.Errorf("read methodSize failed:%w", err)}method := make([]byte, methodSize)_, err = io.ReadFull(reader, method)if err != nil {return fmt.Errorf("read method failed:%w", err)}log.Println("ver", ver, "method", method)// +----+--------+// |VER | METHOD |// +----+--------+// | 1  |   1    |// +----+--------+_, err = conn.Write([]byte{socks5Ver, 0x00})if err != nil {return fmt.Errorf("write failed:%w", err)}return nil
}
3.3.3 请求阶段
package mainimport ("bufio""encoding/binary""errors""fmt""io""log""net"
)const socks5Ver = 0x05
const cmdBind = 0x01
const atypeIPV4 = 0x01
const atypeHOST = 0x03
const atypeIPV6 = 0x04func main() {server, err := net.Listen("tcp", "127.0.0.1:1080")if err != nil {panic(err)}for {client, err := server.Accept()if err != nil {log.Printf("Accept failed %v", err)continue}go process(client)}
}func process(conn net.Conn) {defer conn.Close()reader := bufio.NewReader(conn)err := auth(reader, conn)if err != nil {log.Printf("client %v auth failed:%v", conn.RemoteAddr(), err)return}err = connect(reader, conn)if err != nil {log.Printf("client %v auth failed:%v", conn.RemoteAddr(), err)return}
}func auth(reader *bufio.Reader, conn net.Conn) (err error) {// +----+----------+----------+// |VER | NMETHODS | METHODS  |// +----+----------+----------+// | 1  |    1     | 1 to 255 |// +----+----------+----------+// VER: 协议版本,socks5为0x05// NMETHODS: 支持认证的方法数量// METHODS: 对应NMETHODS,NMETHODS的值为多少,METHODS就有多少个字节。RFC预定义了一些值的含义,内容如下:// X’00’ NO AUTHENTICATION REQUIRED// X’02’ USERNAME/PASSWORDver, err := reader.ReadByte()if err != nil {return fmt.Errorf("read ver failed:%w", err)}if ver != socks5Ver {return fmt.Errorf("not supported ver:%v", ver)}methodSize, err := reader.ReadByte()if err != nil {return fmt.Errorf("read methodSize failed:%w", err)}method := make([]byte, methodSize)_, err = io.ReadFull(reader, method)if err != nil {return fmt.Errorf("read method failed:%w", err)}// +----+--------+// |VER | METHOD |// +----+--------+// | 1  |   1    |// +----+--------+_, err = conn.Write([]byte{socks5Ver, 0x00})if err != nil {return fmt.Errorf("write failed:%w", err)}return nil
}func connect(reader *bufio.Reader, conn net.Conn) (err error) {// +----+-----+-------+------+----------+----------+// |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |// +----+-----+-------+------+----------+----------+// | 1  |  1  | X'00' |  1   | Variable |    2     |// +----+-----+-------+------+----------+----------+// VER 版本号,socks5的值为0x05// CMD 0x01表示CONNECT请求// RSV 保留字段,值为0x00// ATYP 目标地址类型,DST.ADDR的数据对应这个字段的类型。//   0x01表示IPv4地址,DST.ADDR为4个字节//   0x03表示域名,DST.ADDR是一个可变长度的域名// DST.ADDR 一个可变长度的值// DST.PORT 目标端口,固定2个字节buf := make([]byte, 4)_, err = io.ReadFull(reader, buf)if err != nil {return fmt.Errorf("read header failed:%w", err)}ver, cmd, atyp := buf[0], buf[1], buf[3]if ver != socks5Ver {return fmt.Errorf("not supported ver:%v", ver)}if cmd != cmdBind {return fmt.Errorf("not supported cmd:%v", cmd)}addr := ""switch atyp {case atypeIPV4:_, err = io.ReadFull(reader, buf)if err != nil {return fmt.Errorf("read atyp failed:%w", err)}addr = fmt.Sprintf("%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3])case atypeHOST:hostSize, err := reader.ReadByte()if err != nil {return fmt.Errorf("read hostSize failed:%w", err)}host := make([]byte, hostSize)_, err = io.ReadFull(reader, host)if err != nil {return fmt.Errorf("read host failed:%w", err)}addr = string(host)case atypeIPV6:return errors.New("IPv6: no supported yet")default:return errors.New("invalid atyp")}_, err = io.ReadFull(reader, buf[:2])if err != nil {return fmt.Errorf("read port failed:%w", err)}port := binary.BigEndian.Uint16(buf[:2])log.Println("dial", addr, port)// +----+-----+-------+------+----------+----------+// |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |// +----+-----+-------+------+----------+----------+// | 1  |  1  | X'00' |  1   | Variable |    2     |// +----+-----+-------+------+----------+----------+// VER socks版本,这里为0x05// REP Relay field,内容取值如下 X’00’ succeeded// RSV 保留字段// ATYPE 地址类型// BND.ADDR 服务绑定的地址// BND.PORT 服务绑定的端口DST.PORT_, err = conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0, 0})if err != nil {return fmt.Errorf("write failed: %w", err)}return nil
}
3.3.4 relay 阶段
package mainimport ("bufio""context""encoding/binary""errors""fmt""io""log""net"
)const socks5Ver = 0x05
const cmdBind = 0x01
const atypeIPV4 = 0x01
const atypeHOST = 0x03
const atypeIPV6 = 0x04func main() {server, err := net.Listen("tcp", "127.0.0.1:1080")if err != nil {panic(err)}for {client, err := server.Accept()if err != nil {log.Printf("Accept failed %v", err)continue}go process(client)}
}func process(conn net.Conn) {defer conn.Close()reader := bufio.NewReader(conn)err := auth(reader, conn)if err != nil {log.Printf("client %v auth failed:%v", conn.RemoteAddr(), err)return}err = connect(reader, conn)if err != nil {log.Printf("client %v auth failed:%v", conn.RemoteAddr(), err)return}
}func auth(reader *bufio.Reader, conn net.Conn) (err error) {// +----+----------+----------+// |VER | NMETHODS | METHODS  |// +----+----------+----------+// | 1  |    1     | 1 to 255 |// +----+----------+----------+// VER: 协议版本,socks5为0x05// NMETHODS: 支持认证的方法数量// METHODS: 对应NMETHODS,NMETHODS的值为多少,METHODS就有多少个字节。RFC预定义了一些值的含义,内容如下:// X’00’ NO AUTHENTICATION REQUIRED// X’02’ USERNAME/PASSWORDver, err := reader.ReadByte()if err != nil {return fmt.Errorf("read ver failed:%w", err)}if ver != socks5Ver {return fmt.Errorf("not supported ver:%v", ver)}methodSize, err := reader.ReadByte()if err != nil {return fmt.Errorf("read methodSize failed:%w", err)}method := make([]byte, methodSize)_, err = io.ReadFull(reader, method)if err != nil {return fmt.Errorf("read method failed:%w", err)}// +----+--------+// |VER | METHOD |// +----+--------+// | 1  |   1    |// +----+--------+_, err = conn.Write([]byte{socks5Ver, 0x00})if err != nil {return fmt.Errorf("write failed:%w", err)}return nil
}func connect(reader *bufio.Reader, conn net.Conn) (err error) {// +----+-----+-------+------+----------+----------+// |VER | CMD |  RSV  | ATYP | DST.ADDR | DST.PORT |// +----+-----+-------+------+----------+----------+// | 1  |  1  | X'00' |  1   | Variable |    2     |// +----+-----+-------+------+----------+----------+// VER 版本号,socks5的值为0x05// CMD 0x01表示CONNECT请求// RSV 保留字段,值为0x00// ATYP 目标地址类型,DST.ADDR的数据对应这个字段的类型。//   0x01表示IPv4地址,DST.ADDR为4个字节//   0x03表示域名,DST.ADDR是一个可变长度的域名// DST.ADDR 一个可变长度的值// DST.PORT 目标端口,固定2个字节buf := make([]byte, 4)_, err = io.ReadFull(reader, buf)if err != nil {return fmt.Errorf("read header failed:%w", err)}ver, cmd, atyp := buf[0], buf[1], buf[3]if ver != socks5Ver {return fmt.Errorf("not supported ver:%v", ver)}if cmd != cmdBind {return fmt.Errorf("not supported cmd:%v", cmd)}addr := ""switch atyp {case atypeIPV4:_, err = io.ReadFull(reader, buf)if err != nil {return fmt.Errorf("read atyp failed:%w", err)}addr = fmt.Sprintf("%d.%d.%d.%d", buf[0], buf[1], buf[2], buf[3])case atypeHOST:hostSize, err := reader.ReadByte()if err != nil {return fmt.Errorf("read hostSize failed:%w", err)}host := make([]byte, hostSize)_, err = io.ReadFull(reader, host)if err != nil {return fmt.Errorf("read host failed:%w", err)}addr = string(host)case atypeIPV6:return errors.New("IPv6: no supported yet")default:return errors.New("invalid atyp")}_, err = io.ReadFull(reader, buf[:2])if err != nil {return fmt.Errorf("read port failed:%w", err)}port := binary.BigEndian.Uint16(buf[:2])dest, err := net.Dial("tcp", fmt.Sprintf("%v:%v", addr, port))if err != nil {return fmt.Errorf("dial dst failed:%w", err)}defer dest.Close()log.Println("dial", addr, port)// +----+-----+-------+------+----------+----------+// |VER | REP |  RSV  | ATYP | BND.ADDR | BND.PORT |// +----+-----+-------+------+----------+----------+// | 1  |  1  | X'00' |  1   | Variable |    2     |// +----+-----+-------+------+----------+----------+// VER socks版本,这里为0x05// REP Relay field,内容取值如下 X’00’ succeeded// RSV 保留字段// ATYPE 地址类型// BND.ADDR 服务绑定的地址// BND.PORT 服务绑定的端口DST.PORT_, err = conn.Write([]byte{0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0, 0})if err != nil {return fmt.Errorf("write failed: %w", err)}ctx, cancel := context.WithCancel(context.Background())defer cancel()go func() {_, _ = io.Copy(dest, reader)cancel()}()go func() {_, _ = io.Copy(conn, dest)cancel()}()<-ctx.Done()return nil
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/14308.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

自动化测试框架的搭建详解

&#x1f345; 点击文末小卡片 &#xff0c;免费获取软件测试全套资料&#xff0c;资料在手&#xff0c;涨薪更快 最近好多小伙伴都在说接口自动化测试&#xff0c;那么究竟什么是接口自动化测试呢&#xff1f;让我们一起往下看就知道了&#xff0c;首先我们得先弄清楚下面这…

重拾CSS,前端样式精读-媒体查询

前言 本文收录于CSS系列文章中&#xff0c;欢迎阅读指正 说到媒体查询&#xff0c;大家首先想到的可能是有关响应式的知识点&#xff0c;除此之外&#xff0c;它还可以用于条件加载资源&#xff0c;字体大小&#xff0c;图像和视频的优化&#xff0c;用户界面调整等等方面&am…

4TS Series TVS 的解析

4TS Series 400W Transient Voltage Suppressor指的是时源芯微&#xff08;TimeSource&#xff09;生产的一系列瞬态电压抑制二极管&#xff08;Transient Voltage Suppressor&#xff0c;TVS&#xff09;&#xff0c;这些二极管专门设计用于保护敏感电子设备免受雷电、电源浪涌…

语义分割数据增强,图像和标签同步对应详细增强教程(附代码)

&#x1f4aa; 专业从事且热爱图像处理&#xff0c;图像处理专栏更新如下&#x1f447;&#xff1a; &#x1f4dd;《图像去噪》 &#x1f4dd;《超分辨率重建》 &#x1f4dd;《语义分割》 &#x1f4dd;《风格迁移》 &#x1f4dd;《目标检测》 &#x1f4dd;《图像增强》 &a…

本地部署 OpenHands

本地部署 OpenHands 0. 引言1. 部署 OpenHands2. 访问 OpenHands3. 验证 OpenHands 0. 引言 OpenHands 是一个由人工智能驱动的软件开发代理平台。 OpenHands 代理可以执行人类开发人员可以执行的任何操作&#xff1a;修改代码、运行命令、浏览网页、调用 API&#xff0c;甚至…

amber分子动力学

分子动力学模拟是分子模拟中最接近实验条件的模拟方法&#xff0c;能够从原子层面给出体系的微观演变过程&#xff0c;直观的展示实验现象发生的机理与规律&#xff0c;促使学术研究向着更高效、更经济、更有预见性的方向发展。可以解决和研究DNA的折叠和性质、蛋白与配体的识别…

丹摩征文活动 |通过Pycharm复现命名实体识别模型--MECT模型

文章目录 &#x1f34b;1 引言&#x1f34b;2 平台优势&#x1f34b;3 丹摩平台服务器配置教程&#x1f34b;4 实操案例&#xff08; MECT4CNER-main&#xff09;&#x1f34b;4.1 MECT4CNER-main模型&#x1f34b;4.2 环境配置&#x1f34b;4.3 训练模型&#x1f34b;4.4 数据…

嵌入式系统的利器C++

一、嵌入式 C 概述 嵌入式 C 在嵌入式系统开发中占据着至关重要的地位。它是 C 的一个子集&#xff0c;由日本 CPU 大厂于 1996 年提出&#xff0c;目标是在保持 C 面向对象特性的同时&#xff0c;减小代码体积、提升执行效率并简化编译器。 在嵌入式系统开发中&#xff0c;嵌…

【计算机网络】【网络层】【习题】

计算机网络-传输层-习题 文章目录 13. 图 4-69 给出了距离-向量协议工作过程&#xff0c;表&#xff08;a&#xff09;是路由表 R1 初始的路由表&#xff0c;表&#xff08;b&#xff09;是相邻路由器 R2 传送来的路由表。请写出 R1 更新后的路由表&#xff08;c&#xff09;。…

C/C++精品项目之图床共享云存储(2):MySql连接池

一&#xff1a;介绍 C/C精品项目之图床共享云存储&#xff08;1&#xff09; 我们项目的第一个文章讲解了很多的基础组件&#xff0c;包括线程池。我们都知道线程池是为了资源的复用&#xff0c;提高效率。而我们的MySql连接池也是一样的&#xff0c;是为了维持管理固定数量的…

网安数学基础-同余关系

文章目录 参考等价关系实例 同余同余和等价同余的运算 乘法逆元一次同余方程消去律 剩余类中国剩余定理欧拉函数欧拉定理 费马小定理 参考 【一口气学完】密码学的数学基础2&#xff0c;《同余关系》&#xff0c;一小时学完 等价关系 三角形里的全等关系 等价关系定义 下面这…

工业主板市场现状和主要市场驱动因素概述

工业主板市场是计算机硬件行业中的一个重要细分市场&#xff0c;专注于供应专为工业应用而设计的主板。与消费级主板不同&#xff0c;工业主板可承受极端条件&#xff0c;包括高温、连续运行以及暴露在灰尘和潮湿环境中。工业主板对于制造、自动化、医疗、国防和能源等行业中使…

舌尖上的传统美味 —— 食家巷白吉饼

第一眼看到食家巷白吉饼&#xff0c;就被它朴实的外表所吸引。圆润的形状&#xff0c;淡淡的麦色&#xff0c;没有过多的装饰&#xff0c;却散发着一种让人安心的质朴之美。 &#x1f388;拿起一个白吉饼&#xff0c;轻轻一掰&#xff0c;“咔” 的一声&#xff0c;那酥脆的外…

OpenHarmony-1.启动流程

OpenHarmony启动流程 1.kernel的启动 流程图如下所示&#xff1a;   OpenHarmony(简称OH)的标准系统的底层系统是linux&#xff0c;所以调用如下代码&#xff1a; linux-5.10/init/main.c: noinline void __ref rest_init(void) {struct task_struct *tsk;int pid;rcu_sch…

ANR分析实例

目录 一、ANR出的问题原因 二、日志分析 2.1 CPU 负载 2.2 内存 2.3 堆栈信息 三、案例分析 3.1 主线程无卡顿&#xff0c;处于正常状态堆栈 3.2 主线程执行耗时操作 3.3 主线程被锁阻塞 3.4 CPU被抢占 3.5 内存紧张导致ANR 3.6 系统服务超时导致ANR 3.7 Input dis…

知识库搭建:高企创新创业的智慧引擎与未来趋势

在当今这个科技迅猛发展的时代&#xff0c;高新技术企业&#xff08;简称“高企”&#xff09;作为推动经济社会进步的重要力量&#xff0c;正面临着前所未有的创新挑战与机遇。知识库&#xff0c;这一信息时代的关键工具&#xff0c;不仅汇聚了高企内部的丰富知识与经验&#…

D67【python 接口自动化学习】- python基础之数据库

day67 Python操作MySQL基础使用 学习日期&#xff1a;20241113 学习目标&#xff1a;MySQL数据库-- 136 Python操作MySQL基础使用 学习笔记&#xff1a; pymysql 创建MySQL的数据库链接 执行sql语句 总结 Python中使用第三方库&#xff1a;pymysql来操作MySQL&#xff0c;…

容器管理平台KubeSphere的使用

在之前的课程中我们是在minikube中安装了K8S环境,然后通过kubectl命令来管理K8S的,这种用命令来管理的方式虽然对程序员来说看起来很炫酷,但有时候用起来还是挺麻烦的。这节课程给大家介绍一款企业级容器管理平台KubeSphere,使用它能更方便地管理K8S中的容器,希望对大家有…

低代码可视化-uniapp气泡弹窗组件可视化-代码生成器

气泡弹窗组件是产品设计中常用的控件之一&#xff0c;以下是对uniapp气泡弹窗组件可视化的详细解析&#xff1a; 一、组件定义 气泡弹窗组件&#xff08;diy-popover &#xff09;指的是当触发某项操作时&#xff0c;在页面上方或特定位置展示的弹出层容器&#xff0c;容器内…

Unity3D学习FPS游戏(11)敌人AI巡逻(NavMesh)

前言&#xff1a;前面两篇博客已经实现了简单的敌人&#xff0c;但是呢&#xff0c;这样很无趣。因为敌人只会站在原地被攻击&#xff0c;所以本篇我们将实现敌人AI巡逻&#xff0c;让敌人动起来。 敌人AI巡逻 场景丰富一下导航网格NavMesh构建导航网格导航网格优化玩家被当作…