commit a0e4e38a6636430707a22735e16b670e5d059e22 Author: lwl0608 Date: Sat May 11 17:15:31 2024 +0800 fix diff --git a/app b/app new file mode 100755 index 0000000..2031324 Binary files /dev/null and b/app differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b3248fd --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module liwanglin + +go 1.21.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..999d152 --- /dev/null +++ b/main.go @@ -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) + } +}