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

CSDIY:这是一个非科班学生的努力之路,从今天开始这个系列会长期更新,(最好做到日更),我会慢慢把自己目前对CS的努力逐一上传,帮助那些和我一样有着梦想的玩家取得胜利!!!
第一弹:Cpp零基础学习【30 DAYS 从0到1】
第二弹:Cpp刷题文档【LeetCode】
第三弹: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.rhkb.cn/news/473545.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【分布式】万字图文解析——深入七大分布式事务解决方案

分布式事务 分布式事务是指跨多个独立服务或系统的事务管理&#xff0c;以确保这些服务中的数据变更要么全部成功&#xff0c;要么全部回滚&#xff0c;从而保证数据的一致性。在微服务架构和分布式系统中&#xff0c;由于业务逻辑往往会跨多个服务&#xff0c;传统的单体事务…

SystemVerilog学习笔记(十一):接口

在Verilog中&#xff0c;模块之间的通信是使用模块端口指定的。 Verilog模块连接的缺点 声明必须在多个模块中重复。存在声明不匹配的风险。设计规格的更改可能需要修改多个模块。 接口 SystemVerilog引入了 interface 结构&#xff0c;它封装了模块之间的通信。一个 inter…

ARM 汇编指令

blr指令的基本概念和用途 在 ARM64 汇编中&#xff0c;blr是 “Branch with Link to Register” 的缩写。它是一种分支指令&#xff0c;主要用于跳转到一个由寄存器指定的地址&#xff0c;并将返回地址保存到链接寄存器&#xff08;Link Register&#xff0c;LR&#xff09;中。…

pycharm分支提交操作

一、Pycharm拉取Git远程仓库代码 1、点击VCS > Get from Version Control 2、输入git的url&#xff0c;选择自己的项目路径 3、点击Clone&#xff0c;就拉取成功了 默认签出分支为main 选择develop签出即可进行开发工作 二、创建分支&#xff08;非必要可以不使用&#xf…

【MySQL】优化方向+表连接

目录 数据库表连接 表的关系与外键 数据库设计 规范化 反规范化 事务一致性 表优化 索引优化 表结构优化 查询优化 数据库表连接 表的关系与外键 表之间的关系 常见表关系总结 一对一关系&#xff1a;每一条记录在表A中对应表B的唯一一条记录&#xff0c;反之也是&a…

【数据库】mysql数据库迁移前应如何备份数据?

MySQL 数据库的备份是确保数据安全的重要措施之一。在进行数据库迁移之前&#xff0c;备份现有数据可以防止数据丢失或损坏。以下是一套详细的 MySQL 数据库备份步骤&#xff0c;适用于大多数情况。请注意&#xff0c;具体的命令和工具可能因 MySQL 版本的不同而有所差异。整个…

mybatis 动态SQL语句

10. 动态SQL 10.1. 介绍 什么是动态SQL&#xff1a;动态SQL指的是根据不同的查询条件 , 生成不同的Sql语句. 官网描述&#xff1a;MyBatis 的强大特性之一便是它的动态 SQL。如果你有使用 JDBC 或其它类似框架的经验&#xff0c;你就能体会到根据不同条件拼接 SQL 语句的痛苦…

shell脚本_永久环境变量和字符串操作

一、永久环境变量 1. 常见的环境变量 2. 设置永久环境变量 3.1.将脚本加进PATH变量的目录中 3.2.添加进环境变量里 3.2.修改用户的 shell 配置文件 二、字符串操作 1. 字符串拼接 2. 字符串切片 3. 字符串查找 4. 字符串替换 5. 字符串大小写转换 6. 字符串分割 7…

【Go】-bufio库解读

目录 Reader和Writer接口 bufio.Reader/Writer 小结 其他函数-Peek、fill Reader小结 Writer Scanner结构体 缓冲区对于网络数据读写的重要性 Reader和Writer接口 在net/http包生成的Conn 接口的实例中有两个方法叫做Read和Write接口 type Conn interface {Read(b []b…

场景营销在企业定制开发 AI 智能名片 S2B2C 商城小程序中的应用与价值

摘要&#xff1a;本文深入剖析了品牌广告效果不佳与场景营销缺失之间的内在联系&#xff0c;阐述了场景营销对于品牌落地和转化的关键意义。同时&#xff0c;详细探讨了如何将场景营销理念与实践应用于企业定制开发的 AI 智能名片 S2B2C 商城小程序中&#xff0c;借助移动时代的…

uniapp 实现tabbar分类导航及滚动联动效果

思路&#xff1a;使用两个scroll-view&#xff0c;tabbar分类导航使用scrollleft移动&#xff0c;内容联动使用页面滚动onPageScroll监听滚动高度 效果图 <template><view class"content" ><view :class"[isSticky ? tab-sticky: ]">…

Flutter中的Material Theme完全指南:从入门到实战

Flutter作为一款热门的跨平台开发框架&#xff0c;其UI组件库Material Design深受开发者喜爱。本文将深入探讨Flutter Material Theme的使用&#xff0c;包括如何借助Material Theme Builder创建符合产品需求的主题风格。通过多个场景和代码实例&#xff0c;让你轻松掌握这一工…

aws中AcmClient.describeCertificate返回值中没有ResourceRecord

我有一个需求&#xff0c;就是让用户自己把自己的域名绑定我们的提供的AWS服务器。 AWS需要验证证书 上一篇文章中我用php的AcmClient中的requestCertificate方法申请到了证书。 $acmClient new AcmClient([region > us-east-1,version > 2015-12-08,credentials>[/…

Oracle 19c PDB克隆后出现Warning: PDB altered with errors受限模式处理

在进行一次19c PDB克隆过程中&#xff0c;发现克隆结束&#xff0c;在打开后出现了报错&#xff0c;PDB变成受限模式&#xff0c;以下是分析处理过程 09:25:48 SQL> alter pluggable database test1113 open instancesall; Warning: PDB altered with errors. Elapsed: 0…

【3D Slicer】的小白入门使用指南九

定量医学影像临床研究与实践 任务 定量成像教程 定量成像是从医学影像中提取定量测量的过程。 本教程基于两个定量成像的例子构建: - 形态学:缓慢生长肿瘤中的小体积变化 - 功能:鳞状细胞癌中的代谢活动 第1部分:使用变化跟踪模块测量脑膜瘤的小体积变化第2部分:使用PET标…

二、神经网络基础与搭建

神经网络基础 前言一、神经网络1.1 基本概念1.2 工作原理 二、激活函数2.1 sigmoid激活函数2.1.1 公式2.1.2 注意事项 2.2 tanh激活函数2.2.1 公式2.2.2 注意事项 2.3 ReLU激活函数2.3.1 公式2.3.2 注意事项 2.4 SoftMax激活函数2.4.1 公式2.4.2 Softmax的性质2.4.3 Softmax的应…

VMWare虚拟机安装华为欧拉系统

记录一下安装步骤&#xff1a; 1.在vmware中创建一个新的虚拟机&#xff0c;步骤和创建centos差不多 2.启动系统 具体的看下图&#xff1a; 启动虚拟机 耐心等待 等待进度条走完重启系统就完成了

如何进入python交互界面

Python交互模式有两种&#xff1a;图形化的交互模式或者命令行的交互模式。 打开步骤&#xff1a; 首先点击开始菜单。 然后在搜索栏中输入Python&#xff0c;即可看到图形化的交互模式&#xff08;IDLE&#xff08;Python 3.7 64-bit&#xff09;&#xff09;与命令行的交互…

NVR录像机汇聚管理EasyNVR多品牌NVR管理工具视频汇聚技术在智慧安防监控中的应用与优势

随着信息技术的快速发展和数字化时代的到来&#xff0c;安防监控领域也在不断进行技术创新和突破。NVR管理平台EasyNVR作为视频汇聚技术的领先者&#xff0c;凭借其强大的视频处理、汇聚与融合能力&#xff0c;展现出了在安防监控领域巨大的应用潜力和价值。本文将详细介绍Easy…

【STM32】USB 简要驱动软件架构图

STM32 USB 软件架构比较复杂&#xff0c;建议去看 UM 1734 或者 st wiki STM32 USB call graph STM32 USB Device Library files organization Reference [1]: https://wiki.stmicroelectronics.cn/stm32mcu/wiki/Introduction_to_USB_with_STM32 [2]: UM1734