1. 程式人生 > 實用技巧 >Code is already running!

Code is already running!

package main

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

// w表示response物件,返回給客戶端的內容都在物件裡處理
// r表示客戶端請求物件,包含了請求頭,請求引數等等
func index(w http.ResponseWriter, r *http.Request) {
    // 往w裡寫入內容,就會在瀏覽器裡輸出
    fmt.Fprintf(w, "Hello golang http!")
}

func main() {
    // 設定路由,如果訪問/,則呼叫index方法
    http.HandleFunc(
"/", index) // 啟動web服務,監聽9090埠 err := http.ListenAndServe(":1080", nil) if err != nil { log.Fatal("ListenAndServe: ", err) } }

在瀏覽器上輸入:http://localhost:1080/

出現如下圖:

#################################################

但是用vscode來執行程式老是出現:Code is already running!

最近使用visual studio 開發,在運行了 run code 之後,再次執行 ,總提示Code is already running!

最終在輸出視窗 :右鍵 :stop code run

###############################################