vscode 安装

1. go env -w GO111MODULE=on
2. go env -w GOFLAGS=-mod=mod"
2.go env -w GOPROXY=https://goproxy.io,direct
3. 安装 gin 包 go get github.com/gin-gonic/gin

下载vscode

windows shift+ctrl+p

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
go.json

   "go.useLanguageServer": true,
    "timeline.excludeSources": [],

    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    
    "gopls": {
        "completeUnimported": true,
        "usePlaceholders": true,
        "completionDocumentation": true,
        "deepCompletion": true, 
        "matcher": "fuzzy",
        "hoverKind": "SynopsisDocumentation" // No/Synopsis/Full, default Synopsis
    },
    
    "files.eol": " ", // formatting only supports LF line endings

    "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
    },
    "emmet.excludeLanguages": [
    
        "markdown"
    ],
    "go.addTags": {
    
    }

或者

点击go插件extensions settings, 打开.vscode/settings.json,

需要打开以下开关,支持本地包自动补全
“deepCompletion”: true,
“matcher”: “fuzzy”,

settings.json配置示例如下:

   "go.useLanguageServer": true,
    "timeline.excludeSources": [],

    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    
    "gopls": {
        "completeUnimported": true,
        "usePlaceholders": true,
        "completionDocumentation": true,
        "deepCompletion": true, 
        "matcher": "fuzzy",
        "hoverKind": "SynopsisDocumentation" // No/Synopsis/Full, default Synopsis
    },
    
    "files.eol": " ", // formatting only supports LF line endings

    "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
    },
    "emmet.excludeLanguages": [
    
        "markdown"
    ],
    "go.addTags": {
    
    }

最终

{
	// Place your snippets for go here. Each snippet is defined under a snippet name and has a prefix, body and 
	// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
	// same ids are connected.
	// Example:
	// "Print to console": {
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"println":{
		"prefix": "pln",
		"body":"fmt.Println($0)",
		"description": "println"
	},
	"printf":{
		"prefix": "plf",
		"body": "fmt.Printf(\"$0\")",
		"description": "printf"
	},

	"go.useLanguageServer": true,
    "timeline.excludeSources": [],

    "[go]": {
        "editor.snippetSuggestions": "none",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    
    "gopls": {
        "completeUnimported": true,
        "usePlaceholders": true,
        "completionDocumentation": true,
        "deepCompletion": true, 
        "matcher": "fuzzy",
        "hoverKind": "SynopsisDocumentation" // No/Synopsis/Full, default Synopsis
    },
    
    "files.eol": " ", // formatting only supports LF line endings

    "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
    },
    "emmet.excludeLanguages": [
    
        "markdown"
    ],
    "go.addTags": {
    
    },
    "python.jediEnabled": false
	
}