-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
38 lines (32 loc) · 861 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
package main
import (
"context"
"fmt"
"github.com/ehsaniara/gointerlock"
"log"
"net/http"
"time"
)
func main() {
cnx := context.Background()
var expensiveQueryResult = fmt.Sprintf("Last result at: %v", time.Now())
//introduced the task
go func() {
//setting up the scheduler parameter
var job = gointerlock.GoInterval{
LockVendor: gointerlock.SingleApp, //optional
Interval: 5 * time.Second,
Arg: func() {
expensiveQueryResult = fmt.Sprintf("Last result at: %v", time.Now())
},
}
// start the scheduler
_ = job.Run(cnx)
}()
// http Server, access http://localhost:8080 from your browser
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
_, _ = fmt.Fprintln(writer, expensiveQueryResult)
})
fmt.Println("Server started at port 8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}