更新 'main.go'
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
3f42d3db63
commit
24f84ebdde
@ -1,12 +1,33 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"log"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(HelloWorld())
|
||||
}
|
||||
|
||||
// HelloWorld is a function that returns a string containing "hello world".
|
||||
func HelloWorld() string {
|
||||
return "hello world"
|
||||
}
|
||||
|
||||
func sayhelloName(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm() // 解析参数,默认是不会解析的
|
||||
fmt.Println(r.Form) // 这些信息是输出到服务器端的打印信息
|
||||
fmt.Println("path", r.URL.Path)
|
||||
fmt.Println("scheme", r.URL.Scheme)
|
||||
fmt.Println(r.Form["url_long"])
|
||||
for k, v := range r.Form {
|
||||
fmt.Println("key:", k)
|
||||
fmt.Println("val:", strings.Join(v, ""))
|
||||
}
|
||||
fmt.Fprintf(w, "Hello astaxie!") // 这个写入到 w 的是输出到客户端的
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", sayhelloName) // 设置访问的路由
|
||||
err := http.ListenAndServe(":8080", nil) // 设置监听的端口
|
||||
if err != nil {
|
||||
log.Fatal("ListenAndServe: ", err)
|
||||
}
|
||||
}
|
Loading…
Reference in new issue