vscode无法格式化go代码

安装 golang.org/x/tools/imports失败

去GOPATH目录下

cd $GOPATH

下载github上的TOOLS

andrew@DESKTOP-1CLR4DJ /cygdrive/c/Users/andrew/go/src/github.com/golang
$ git clone https://github.com/golang/tools

建立golang.org目录

andrew@DESKTOP-1CLR4DJ /cygdrive/c/Users/andrew/go/src
$ mkdir -p golang.org/x

将github的tools拷贝到golang下

andrew@DESKTOP-1CLR4DJ /cygdrive/c/Users/andrew/go/src
$ cp -r  github.com/golang/tools   golang.org/x/

同样的方式处理 github.com/sqs/goreturns 然后安装

$ go get -v github.com/sqs/goreturns
golang.org/x/tools/internal/semver
golang.org/x/tools/internal/fastwalk
golang.org/x/tools/go/ast/astutil
golang.org/x/tools/internal/module
github.com/sqs/goreturns/returns
golang.org/x/tools/go/internal/gcimporter
golang.org/x/tools/go/internal/packagesdriver
golang.org/x/tools/internal/gopathwalk
golang.org/x/tools/go/gcexportdata
golang.org/x/tools/go/packages
golang.org/x/tools/imports
github.com/sqs/goreturns

 

 

一段服务器代码:

package main

import (
	"fmt"
	"log"
	"net/http"

	"golang.org/x/net/websocket"
)

// "golang.org/x/net/websocket"

func echo(ws *websocket.Conn) {
	var err error

	for {
		var reply string

		if err = websocket.Message.Receive(ws, &reply); err != nil {
			fmt.Println("can not receive")
			break
		}

		fmt.Println("received back from client: " + reply)

		msg := "recieved: " + reply
		fmt.Println("sending to client: " + msg)

		if err = websocket.Message.Send(ws, msg); err != nil {
			fmt.Println("can not send")
			break
		}
	}
}

func main() {
	http.Handle("/", websocket.Handler(echo))

	if err := http.ListenAndServe(":123456", nil); err != nil {
		log.Fatal("listenAndServe: ", err)
	}
}

 

你可能感兴趣的:(go)