Learn go from 0 - HelloWorld

I haven't written goLand for almost two years, and I have almost forgotten it. Write a HelloWorld from 0.

ide

The same series as idea, classic GoLand:

 create a new project

Foolish creation, very cute is that the default project name is: awesomeProject, it is really awesome~

Hello World

Code

package main

import (
	"fmt"
	"net/http"
)

func main() {
	// 绑定 路由"/hello"和处理器函数handleHello
	http.HandleFunc("/hello", handleHello)
	// 输出到系统的标准输出
	fmt.Println("serving on http://localhost:8080/hello")
	// 整个服务运行的总入口
	http.ListenAndServe("localhost:8080", nil)
}
func handleHello(w http.ResponseWriter, req *http.Request) {
	// 将内容输出到一个io.Writer接口类型的变量w中,我们通常用这个函数往文件中写入内容
	fmt.Fprintln(w, "Hello World!")
}

implement

Click the small triangle on the left side of the code

output

page display

 Congratulations, your first awesome go project has been successfully launched~

Guess you like

Origin blog.csdn.net/xue_xiaofei/article/details/128411885