-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (40 loc) · 991 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"flag"
"fmt"
"log"
"net/http"
"time"
)
type conf struct {
Logtest bool
LogIntv int
LogStr string
Port string
}
func main() {
var cfg conf
flag.BoolVar(&cfg.Logtest, "logtest", true, "test log true or false")
flag.IntVar(&cfg.LogIntv, "logintv", 600, "logintv is this app will produce log in each how many second (default 10 minutes)")
flag.StringVar(&cfg.LogStr, "logstr", "this is testing logs", "logintv is this app will produce log like this")
flag.StringVar(&cfg.Port, "port", "8080", "logintv is this app will produce log like this")
flag.Parse()
if cfg.Logtest {
go logs(cfg)
}
run(cfg)
}
func ping(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "%s", "PONG")
}
func run(c conf) {
http.HandleFunc("/ping", ping)
log.Printf("server run at port :%s \n", c.Port)
log.Fatal(http.ListenAndServe(":"+c.Port, nil))
}
func logs(c conf) {
for {
log.Println(c.LogStr)
time.Sleep(time.Duration(c.LogIntv) * time.Second)
}
}