spud/daemon/daemon.go

28 lines
437 B
Go
Raw Normal View History

2024-10-02 02:56:25 +00:00
package daemon
import (
"fmt"
"net/http"
)
type Daemon struct {
Host string
Port int
}
func NewDaemon(host string, port int) *Daemon {
return &Daemon{Host: host, Port: port}
}
func (d Daemon) GetListenAddress() string {
return fmt.Sprintf("%s:%d", d.Host, d.Port)
}
func (d Daemon) Start() {
for route, handler := range GetApiRoutes() {
http.HandleFunc(route, handler)
}
http.ListenAndServe(d.GetListenAddress(), nil)
}