diff --git a/go.mod b/go.mod index 7f6c916..8746a97 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module courgette go 1.23.1 require ( + forge.karnov.club/marc/http-api-kit v0.0.1 github.com/gofrs/uuid v4.4.0+incompatible github.com/spf13/cobra v1.8.1 gopkg.in/yaml.v3 v3.0.1 diff --git a/go.sum b/go.sum index 08446c9..2bda50b 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +forge.karnov.club/marc/http-api-kit v0.0.1 h1:evYR9T7TZU64fDGN/ZsfohXyO8zS2yHrUN6fGmsJVFQ= +forge.karnov.club/marc/http-api-kit v0.0.1/go.mod h1:AbIDCaC8ksKUlXkKegB3JLR2VNgTuIEUNBoKpa5Ck2g= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= diff --git a/internal/daemon/api.go b/internal/daemon/api.go new file mode 100644 index 0000000..6f4b8b1 --- /dev/null +++ b/internal/daemon/api.go @@ -0,0 +1,24 @@ +package daemon + +import ( + httpKit "forge.karnov.club/marc/http-api-kit" +) + +// Representation of the daemon process that services the runner's +// Rest API. +type Daemon struct { + Addr string + Api *httpKit.App +} + +func NewDaemon() *Daemon { + api := httpKit.NewApp() + + return &Daemon{Api: api} +} + +// Starts listening for requests at the given address for +// daemon traffic. +func (d Daemon) Start(addr string) { + d.Api.Start(addr) +} diff --git a/internal/daemon/api_test.go b/internal/daemon/api_test.go new file mode 100644 index 0000000..c78ab79 --- /dev/null +++ b/internal/daemon/api_test.go @@ -0,0 +1,13 @@ +package daemon + +import ( + "testing" +) + +func Test_Daemon_Api_NewDaemonReturnsDaemonInstance(t *testing.T) { + d := NewDaemon() + + if d == nil { + t.Errorf("Expected Daemon instance, got something else: %+v", d) + } +} diff --git a/main.go b/main.go index 0744059..4a2480e 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "context" commands "courgette/internal/commands" + daemon "courgette/internal/daemon" logger "courgette/internal/logging" "github.com/spf13/cobra" "os" @@ -59,9 +60,20 @@ var validate = &cobra.Command{ }, } +var daemonCmd = &cobra.Command{ + Use: "daemon", + Short: "Starts the daemon process", + Run: func(cmd *cobra.Command, args []string) { + // FIXME: Sample daemon setup. + d := daemon.NewDaemon() + d.Start(":8080") + }, +} + var knownCommands = []*cobra.Command{ execute, validate, + daemonCmd, } func main() {