您好,登錄后才能下訂單哦!
本篇文章為大家展示了Windows中go-zero如何使用,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
新增go的代理
GOPROXY=https://goproxy.io,direct,https://mirrors.aliyun.com/goproxy/,https://goproxy.cn,https://athens.azurefd.net,https://gonexus.dev
環境變量path中添加 %GOROOT%\bin;%GOPATH%\bin
安裝插件
關鍵是go語言環境在vscode的配置,如下:
{ "go.goroot": "D:\\go", "go.gopath": "D:\\go_project", "go.inferGopath": false, "go.toolsGopath": "D:\\go_project", "window.zoomLevel": 0, "git.autofetch": true, "terminal.integrated.shell.windows": "powershell.exe", // 也可以使用 cmd.exe "workbench.colorTheme": "Monokai Pro (Filter Machine)", "workbench.iconTheme": "Monokai Pro (Filter Machine) Icons", "editor.renderControlCharacters": false, "editor.snippetSuggestions": "top", "editor.suggest.snippetsPreventQuickSuggestions": true, "breadcrumbs.enabled": true, "terminal.explorerKind": "external", "editor.cursorStyle": "block", "editor.links": false, "editor.mouseWheelZoom": true, "editor.renderLineHighlight": "all", "editor.suggest.shareSuggestSelections": true, "outline.icons": true, "search.showLineNumbers": true, "search.smartCase": true, // package 查找模式 "go.gocodePackageLookupMode": "go", "go.gotoSymbol.includeGoroot": true, "go.gotoSymbol.includeImports": true, // build 相關 "go.buildOnSave": "off", "go.gocodeAutoBuild": true, "go.installDependenciesWhenBuilding": true, "go.buildFlags": [], "go.buildTags": "", "go.coverOnSingleTest": true, "go.useCodeSnippetsOnFunctionSuggest": true, "go.useCodeSnippetsOnFunctionSuggestWithoutType": true, "go.docsTool": "guru", "go.formatTool": "goimports", "go.lintTool": "golangci-lint", "go.lintOnSave": "package", "go.lintFlags": [ "--fast" ], "go.formatFlags": [], "go.vetFlags": [], "go.vetOnSave": "package", "go.generateTestsFlags": [], "go.liveErrors": { "enabled": true, "delay": 500 }, "go.gocodeFlags": [ "-builtin", "-ignore-case", "-unimported-packages" ], "go.enableCodeLens": { "references": true, "runtest": true }, "go.delveConfig": { "dlvLoadConfig": { "followPointers": true, "maxVariableRecurse": 1, "maxStringLen": 64, "maxArrayValues": 64, "maxStructFields": -1 }, "apiVersion": 2, "showGlobalVariables": true }, "go.editorContextMenuCommands": { "toggleTestFile": true, "addTags": true, "removeTags": true, "testAtCursor": true, "testFile": true, "testPackage": true, "generateTestForFunction": true, "generateTestForFile": true, "generateTestForPackage": true, "addImport": true, "testCoverage": true, "playground": true, "debugTestAtCursor": true }, "go.playground": { "openbrowser": false, "share": false, "run": false }, "go.addTags": { "tags": "json", "options": "json=omitempty", "promptForTags": true, "transform": "snakecase" }, "go.removeTags": { "tags": "", "options": "", "promptForTags": false }, "[go]": { "editor.codeActionsOnSave": { "source.organizeImports": true }, }, "go.alternateTools": { "go-langserver": "gopls", }, "go.useLanguageServer": false, "go.languageServerFlags": [], "go.languageServerExperimentalFeatures": { "format": true, "autoComplete": true, "rename": true, "goToDefinition": true, "hover": true, "signatureHelp": true, "goToTypeDefinition": true, "goToImplementation": true, "documentSymbols": true, "workspaceSymbols": true, "findReferences": true, "diagnostics": false } }
參考鏈接:https://www.cnblogs.com/chnmig/p/10796316.html
github地址:https://github.com/tal-tech/go-zero
學習視頻地址:https://talkgo.org/t/topic/729
語雀文檔資料:https://www.yuque.com/tal-tech/go-zero/tdsgkg
goctl是go-zero微服務框架下的代碼生成工具,其可以快速提升開發效率,讓開發人員將時間重點放在業務coding上……
查詢很多資料都不說的,不清晰,總是報command not found: goctl錯誤。
我也是將goctl工具安裝到 $GOPATH/bin
目錄下
?x-oss-
環境變量也配置了,最后發現,所有網上博客都沒有說,把 $GOPATH/bin
,加入系統環境path變量。加入以后,重啟電腦,就可以正常使用goctl工具。
接下來,就是體驗goctl工具。
C:\Users\domin>d: D:\>cd D:\go-learn D:\go-learn>goctl api new greet [32mDone.[0m D:\go-learn>cd greet D:\go-learn\greet>go mod init go mod init: go.mod already exists D:\go-learn\greet>go mod tidy go: finding module for package github.com/tal-tech/go-zero/core/logx go: finding module for package github.com/tal-tech/go-zero/rest go: finding module for package github.com/tal-tech/go-zero/rest/httpx go: finding module for package github.com/tal-tech/go-zero/core/conf go: found github.com/tal-tech/go-zero/core/conf in github.com/tal-tech/go-zero v1.1.2 go: found github.com/tal-tech/go-zero/rest in github.com/tal-tech/go-zero v1.1.2 go: found github.com/tal-tech/go-zero/rest/httpx in github.com/tal-tech/go-zero v1.1.2 go: found github.com/tal-tech/go-zero/core/logx in github.com/tal-tech/go-zero v1.1.2 D:\go-learn\greet>go run greet.go -f etc/greet-api.yaml Starting server at 0.0.0.0:8888... {"@timestamp":"2021-01-10T01:04:05.746+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:04:05.751+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"} {"@timestamp":"2021-01-10T01:05:05.747+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:05:05.751+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"} {"@timestamp":"2021-01-10T01:06:05.746+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:06:05.750+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"} {"@timestamp":"2021-01-10T01:07:05.746+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:07:05.752+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"} {"@timestamp":"2021-01-10T01:08:05.744+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:08:05.750+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"} {"@timestamp":"2021-01-10T01:09:05.746+08","level":"stat","content":"CPU: 0m, MEMORY: Alloc=0.6Mi, TotalAlloc=0.6Mi, Sys=6.6Mi, NumGC=0"} {"@timestamp":"2021-01-10T01:09:05.750+08","level":"stat","content":"(api) shedding_stat [1m], cpu: 0, total: 0, pass: 0, drop: 0"}
再另外開一個cmd窗口
C:\Users\domin>d: D:\>cd D:\go-learn\greet D:\go-learn\greet>goctl api java -api greet.api -dir greet [32mDone.[0m D:\go-learn\greet>curl -i http://localhost:8888/from/you HTTP/1.1 200 OK Content-Type: application/json Date: Sat, 09 Jan 2021 17:09:06 GMT Content-Length: 14
生成的代碼
除了goctl神器,go-zero還有很多的小工具。
流數據處理利器:fx。如java8的lambda,,go-zero也有了!fx.Filter().Sort().Head() ,讓數組的復雜處理變得簡單。
List itemmapReduce降低服務相應時間:mr.Finish(), mr.Map().Reduce(), 跟并發處理waitGroup說拜拜。
etcd服務發現的集成:p2c的算法發現服務,避免開發人員點對點或nginx的轉發服務,安裝一個etcd就完事了。
jwt集成api:輕松擁有一個jwt的后臺服務。
集成Prometheus:輕松擁有一個帶監控的golang后臺服務。
上述內容就是Windows中go-zero如何使用,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。