{"id":350,"date":"2023-07-05T14:53:13","date_gmt":"2023-07-05T06:53:13","guid":{"rendered":"https:\/\/www.zhidianwl.net\/zhidianwl\/?p=350"},"modified":"2023-07-05T14:53:13","modified_gmt":"2023-07-05T06:53:13","slug":"app%e5%bc%80%e5%8f%91golang%e6%9c%89%e4%bb%80%e4%b9%88%e4%bd%9c%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.zhidianwl.net\/zhidianwl\/2023\/07\/05\/app%e5%bc%80%e5%8f%91golang%e6%9c%89%e4%bb%80%e4%b9%88%e4%bd%9c%e7%94%a8%ef%bc%9f\/","title":{"rendered":"app\u5f00\u53d1golang\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f"},"content":{"rendered":"

Golang\u5e94\u7528\u5f00\u53d1\u5165\u95e8\u6559\u7a0b\uff1a\u7406\u8bba\u4e0e\u5b9e\u8df5\u8be6\u8ff0<\/p>\n

\u4e00\u3001Golang\u7b80\u4ecb<\/p>\n

Golang\uff08Go\u8bed\u8a00\uff09\u662f\u4e00\u95e8\u7531\u8c37\u6b4c\u516c\u53f8\uff08Google\uff09\u5f00\u53d1\u7684\u5f00\u6e90\u9759\u6001\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bbe\u8ba1\u76ee\u7684\u662f\u4e3a\u4e86\u5b9e\u73b0\u7b80\u5355\u3001\u9ad8\u6548\u3001\u6613\u61c2\u7684\u4ee3\u7801\u3002Go\u8bed\u8a00\u7684\u5f00\u53d1\u4e3b\u8981\u7531Robert Griesemer\u3001Rob Pike\u548cKen Thompson\u9886\u5934\uff0c\u4ed6\u4eec\u5e0c\u671b\u5efa\u7acb\u4e00\u95e8\u5177\u6709\u73b0\u4ee3\u5316\u7279\u70b9\u7684\u5e94\u7528\u8bed\u8a00\uff0c\u65e2\u9002\u5408\u65b0\u624b\u5165\u95e8\u5b66\u4e60\uff0c\u4e5f\u9002\u5408\u7f16\u5199\u9ad8\u6027\u80fd\u7684\u7cfb\u7edf\u8f6f\u4ef6\u3002 Golang\u5177\u6709\u4ee5\u4e0b\u7279\u6027\uff1a<\/p>\n

1. \u6613\u4e8e\u5b66\u4e60\u548c\u4f7f\u7528\uff1aGo\u8bed\u8a00\u7684\u8bed\u6cd5\u7b80\u6d01\uff0c\u6613\u4e8e\u4e0a\u624b\uff0c\u91c7\u7528\u4e86Cubature Anxiety\u63a5\u53e3\u98ce\u683c\uff0c\u5e76\u4e14\u62e5\u6709\u5f3a\u5927\u7684\u6807\u51c6\u5e93\u3002<\/p>\n

2. \u5e76\u53d1\u6027\uff1a\u5229\u7528Goroutines\u548cChannels\u673a\u5236\u8f7b\u677e\u5b9e\u73b0\u5e76\u53d1\u7f16\u7a0b\uff0c\u6709\u6548\u63d0\u9ad8\u7a0b\u5e8f\u8fd0\u884c\u6548\u7387\u3002<\/p>\n

3. \u5783\u573e\u56de\u6536\uff1aGo\u63d0\u4f9b\u4e86\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\uff0c\u8ba9\u5f00\u53d1\u4eba\u5458\u4e0d\u518d\u4e3a\u5185\u5b58\u6cc4\u6f0f\u800c\u70e6\u607c\u3002<\/p>\n

4. \u8de8\u5e73\u53f0\u5f00\u53d1\uff1aGo\u4ee3\u7801\u53ef\u76f4\u63a5\u7f16\u8bd1\u4e3a\u591a\u4e2a\u5e73\u53f0\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u65e0\u9700\u501f\u52a9\u5176\u4ed6\u5e73\u53f0\u6216\u5de5\u5177\u3002<\/p>\n

\u4e8c\u3001Golang\u9002\u7528\u573a\u666f<\/p>\n

1. \u540e\u7aef\u5f00\u53d1\uff1a\u5177\u6709\u6781\u9ad8\u7684\u6027\u80fd\uff0c\u9002\u5408\u7f16\u5199\u9ad8\u5e76\u53d1\u7684\u7f51\u7edc\u5e94\u7528\u3001\u5206\u5e03\u5f0f\u7cfb\u7edf\u3001\u5fae\u670d\u52a1\u67b6\u6784\u7b49\u3002<\/p>\n

2. \u7cfb\u7edf\u5de5\u5177\u548c\u5c0f\u5de5\u5177\u5f00\u53d1\uff1aGo\u7b80\u6d01\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u6807\u51c6\u5e93\uff0c\u8ba9\u5b83\u6210\u4e3a\u521b\u5efa\u7cfb\u7edf\u5de5\u5177\u548c\u5c0f\u7a0b\u5e8f\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n

3. \u4e91\u670d\u52a1\uff1a\u8c37\u6b4c\u3001\u4e9a\u9a6c\u900a\u4ee5\u53ca\u5176\u4ed6\u4e00\u4e9b\u5927\u578b\u516c\u53f8\u90fd\u5341\u5206\u652f\u6301Golang\u5f00\u53d1\uff0c\u4f7f\u5176\u6210\u4e3a\u4e91\u670d\u52a1\u9886\u57df\u7684\u70ed\u95e8\u9009\u62e9\u3002<\/p>\n

4. IOT\u7269\u8054\u7f51\uff1aGolang\u7684\u90e8\u7f72\u7b80\u4fbf\u3001\u8de8\u5e73\u53f0\u7f16\u8bd1\u80fd\u529b\uff0c\u4f7f\u5f97\u5176\u5728\u7269\u8054\u7f51\u8bbe\u5907\u4e2d\u5e94\u7528\u4ea6\u5341\u5206\u5e7f\u6cdb\u3002<\/p>\n

\u4e09\u3001Golang\u5f00\u53d1\u73af\u5883\u642d\u5efa<\/p>\n

1. \u5b89\u88c5Go\uff1a\u8bbf\u95ee\u5b98\u7f51\uff08https:\/\/golang.org\/dl\/\uff09\u4e0b\u8f7d\u9002\u7528\u4e8e\u60a8\u64cd\u4f5c\u7cfb\u7edf\u7684\u5b89\u88c5\u5305\uff0c\u5b89\u88c5\u5e76\u914d\u7f6e\u597d\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u3002<\/p>\n

2. \u914d\u7f6eGOPATH\uff1a\u5efa\u8bae\u5c06GOPATH\u73af\u5883\u53d8\u91cf\u6307\u5411\u4e00\u4e2a\u5355\u72ec\u7684\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u7c7b\u4f3c\u4e8e$HOME\/go\u7684\u76ee\u5f55\u8fdb\u884c\u5b58\u50a8\u3002<\/p>\n

3. \u9009\u62e9\u548c\u5b89\u88c5\u4e00\u4e2aIDE\uff1aGo\u8bed\u8a00\u652f\u6301\u591a\u4e2a\u4f18\u79c0\u7684\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff0c\u5982Visual Studio Code\u3001GoLand\u548cAtom\u7b49\u3002<\/p>\n

\u56db\u3001Golang\u5e94\u7528\u5f00\u53d1\u5b9e\u8df5<\/p>\n

1. Hello World<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func main() {<\/p>\n

fmt.Println(“Hello, World!”)<\/p>\n

}<\/p>\n

“`<\/p>\n

2. \u5b9a\u4e49\u53d8\u91cf<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func main() {<\/p>\n

var x int = 10<\/p>\n

y := 20<\/p>\n

fmt.Println(x, y)<\/p>\n

}<\/p>\n

“`<\/p>\n

3. \u63a7\u5236\u8bed\u53e5<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func main() {<\/p>\n

for i := 0; i <\/p>\n

if i%2 == 0 {<\/p>\n

fmt.Println(i, “is even”)<\/p>\n

} else {<\/p>\n

fmt.Println(i, “is odd”)<\/p>\n

}<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

4. \u81ea\u5b9a\u4e49\u51fd\u6570<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

func add(x int, y int) int {<\/p>\n

return x + y<\/p>\n

}<\/p>\n

func main() {<\/p>\n

result := add(10, 20)<\/p>\n

fmtAPP<\/a>.Println(“The result is:”, result)<\/p>\n

}<\/p>\n

“`<\/p>\n

5. \u4f7f\u7528\u7ed3\u6784\u4f53\u548c\u65b9\u6cd5<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import “fmt”<\/p>\n

type Person struct {<\/p>\n

firstName string<\/p>\n

lastName string<\/p>\n

}<\/p>\n

func (p *Person) fullName() string {<\/p>\n

return p.firAPP\u5f00\u53d1<\/a>stName + ” ” + p.lastName<\/p>\n

}<\/p>\n

func main() {<\/p>\n

p := Person{“John”, “Doe”}<\/p>\n

fmt.Println(p.fullName())<\/p>\n

}<\/p>\n

“`<\/p>\n

6. Goroutines\u548cChannels<\/p>\n

“`go<\/p>\n

package main<\/p>\n

import (<\/p>\n

“fmt”<\/p>\n

“time”<\/p>\n

)<\/p>\n

func worker(id int, ch chan int) {<\/p>\n

for {<\/p>\n

fmt.Printf(“Worker %d received a task\\n”, id)<\/p>\n

time.Sleep(time.Second)<\/p>\n

ch <\/p>\n

}<\/p>\n

}<\/p>\n

func main() {<\/p>\n

ch := make(chan int)<\/p>\n

for i := 0; i <\/p>\n

go worker(i, ch)<\/p>\n

}<\/p>\n

for {<\/p>\n

id := <\/p>\n

\n

<\/figure>\n<\/p>\n

fmt.Printf(“Worker %d has finished\\n”, id)<\/p>\n

}<\/p>\n

}<\/p>\n

“`<\/p>\n

\u901a\u8fc7\u4ee5\u4e0a\u7684\u4ecb\u7ecd\u548c\u5b9e\u8df5\u4ee3\u7801\uff0c\u76f8\u4fe1\u60a8\u5df2\u7ecf\u5bf9Golang\u6709\u4e86\u521d\u6b65\u7684\u4e86\u89e3\u3002Golang \u7684\u5b66\u4e60\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u9700\u8981\u4e0d\u65ad\u63a2\u7d22\u548c\u5b9e\u8df5\u6765\u6df1\u5165\u7406\u89e3\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u60a8\u63d0\u4f9b\u542f\u53d1\u548c\u53c2\u8003\uff0c\u52a9\u529b\u60a8\u66f4\u597d\u5730\u5f00\u53d1\u9ad8\u6548\u3001\u7a33\u5b9a\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Golang\u5e94\u7528\u5f00\u53d1\u5165\u95e8\u6559\u7a0b\uff1a\u7406\u8bba\u4e0e\u5b9e\u8df5\u8be6\u8ff0\u4e00\u3001Golang\u7b80\u4ecbGolang\uff08Go\u8bed\u8a00\uff09\u662f\u4e00\u95e8\u7531\u8c37\u6b4c\u516c\u53f8\uff08Google\uff09\u5f00\u53d1\u7684\u5f00\u6e90\u9759\u6001\u7c7b\u578b\u7f16\u7a0b\u8bed\u8a00\uff0c\u8bbe\u8ba1\u76ee\u7684\u662f\u4e3a\u4e86\u5b9e\u73b0\u7b80\u5355\u3001\u9ad8\u6548\u3001\u6613\u61c2\u7684\u4ee3\u7801\u3002Go\u8bed\u8a00<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[835,677,32,834,614],"topic":[],"class_list":{"0":"post-350","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-kaifaapp","7":"tag-exe","8":"tag-677","9":"tag-32","11":"tag-614"},"_links":{"self":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/comments?post=350"}],"version-history":[{"count":0,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/posts\/350\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/media?parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/categories?post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/tags?post=350"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.zhidianwl.net\/zhidianwl\/wp-json\/wp\/v2\/topic?post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}