1.打開Goland,點擊New Project新建一個專案

然后填寫新建專案的工程名,選擇sdk

選擇和設定完成后點擊Create完成創建,選中工程名,單擊右鍵,選擇New->Go File

輸入名稱后回車即可新建一個Go的檔案

Empty file只會添加一個包名,Simple Application則會幫我們自動生成一些代碼,省得我們去手動鍵入
2.下面就開始正式寫代碼了
package main import ( "fmt" "net/http" ) func handler(w http.ResponseWriter,r *http.Request) { fmt.Fprintln(w,"hello world") }
func main() { http.HandleFunc("/",handler) http.ListenAndServe(":8080",nil) }
寫完之后,點擊下圖中綠色的小三角即可運行我們第一個最簡單的服務器程式

我們打開瀏覽器,輸入http://localhost:8080/,即可看到下面的界面

好了,大功告成!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/33527.html
標籤:Go
下一篇:一、 go基礎
