fix
This commit is contained in:
parent
f7e6a6f6b7
commit
ae6679be06
4
main.go
4
main.go
|
@ -12,8 +12,10 @@ func main() {
|
||||||
var host string
|
var host string
|
||||||
var port int
|
var port int
|
||||||
flag.StringVar(&host, "h", GetIp(), "IP地址")
|
flag.StringVar(&host, "h", GetIp(), "IP地址")
|
||||||
flag.IntVar(&port, "p", 9000, "端口")
|
flag.IntVar(&port, "p", 12564, "端口")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
fmt.Println(host)
|
||||||
address := fmt.Sprintf("%s:%d", host, port)
|
address := fmt.Sprintf("%s:%d", host, port)
|
||||||
http.HandleFunc("/ping", func(writer http.ResponseWriter, request *http.Request) {
|
http.HandleFunc("/ping", func(writer http.ResponseWriter, request *http.Request) {
|
||||||
_, _ = fmt.Fprintln(writer, fmt.Sprintf("%s by %s", "pong", address))
|
_, _ = fmt.Fprintln(writer, fmt.Sprintf("%s by %s", "pong", address))
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
quit := make(chan os.Signal)
|
||||||
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
|
||||||
|
<-quit
|
||||||
|
fmt.Println("Shutdown")
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func loop() {
|
||||||
|
resp, err := http.Get("http://nginx-server.tiefen.fun")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("err: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("err: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
for range time.Tick(time.Millisecond * 500) {
|
||||||
|
loop()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue