-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
40 lines (33 loc) · 850 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
package main
import (
"fmt"
"net/http"
"os"
"daemon-set-example.com/logger"
"github.com/sirupsen/logrus"
)
type Server struct {
handler *Handler
}
func NewServer(handler *Handler) *Server {
return &Server{handler: handler}
}
func (s *Server) StartServer(port string) {
mux := http.NewServeMux()
mux.HandleFunc("/tasks", s.handler.HandleTasks)
logrus.Infof("daemon server is running on port %s", port)
if err := http.ListenAndServe(port, mux); err != nil {
fmt.Printf("error starting server: %v", err)
}
}
func main() {
logger.SetLogrus()
port := os.Getenv("DAEMON_SERVER_PORT")
if port == "" {
fmt.Printf("environment variable DAEMON_SERVER_PORT is not set. Cannot start server")
return
}
handler := &Handler{port: port, tasks: make(map[string]chan bool)}
server := NewServer(handler)
server.StartServer(":" + port)
}