This commit is contained in:
lwl0608 2024-05-11 17:15:31 +08:00
commit a0e4e38a66
3 changed files with 29 additions and 0 deletions

BIN
app Executable file

Binary file not shown.

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module liwanglin
go 1.21.1

26
main.go Normal file
View File

@ -0,0 +1,26 @@
package main
import (
"flag"
"fmt"
"net/http"
)
func main() {
var host string
var port int
flag.StringVar(&host, "h", "127.0.0.1", "IP地址")
flag.IntVar(&port, "p", 9000, "端口")
flag.Parse()
address := fmt.Sprintf("%s:%d", host, port)
http.HandleFunc("/ping", func(writer http.ResponseWriter, request *http.Request) {
_, _ = fmt.Fprintln(writer, fmt.Sprintf("%s by %s", "pong", address))
})
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
_, _ = fmt.Fprintln(writer, fmt.Sprintf("%s by %s", "hello world", address))
})
err := http.ListenAndServe(address, nil)
if nil != err {
panic(err)
}
}