-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniqueIDGenerator.go
More file actions
42 lines (35 loc) · 881 Bytes
/
Copy pathuniqueIDGenerator.go
File metadata and controls
42 lines (35 loc) · 881 Bytes
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
package main
import (
"flag"
"fmt"
"net/http"
"github.com/golang/glog"
"github.com/jaichabria/uniqueIDGenerator/metrics"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var uniqueID int
func main() {
flag.Parse()
http.HandleFunc("/getNewId", getUniqueID)
http.Handle("/metrics", promhttp.Handler())
go func() {
err := http.ListenAndServeTLS(":8043", "certs/https-server.crt", "certs/https-server.key", nil)
if err != nil {
glog.Fatal("Unable to start sever: ", err.Error())
}
}()
go func() {
err := http.ListenAndServe(":8080", nil)
if err != nil {
glog.Fatal("Unable to start sever: ", err.Error())
}
}()
glog.Info("Both listeners started succesfully")
glog.Flush()
select {}
}
func getUniqueID(w http.ResponseWriter, req *http.Request) {
uniqueID++
fmt.Fprintf(w, "{\"id\":%d}", uniqueID)
metrics.IncUniqueIDsGenerated()
}