feat: add stub daemon command + api

This commit is contained in:
Marc 2024-10-06 10:58:14 -04:00
parent 44efd478a7
commit d184b2da77
Signed by: marc
GPG key ID: 048E042F22B5DC79
5 changed files with 52 additions and 0 deletions

1
go.mod
View file

@ -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

2
go.sum
View file

@ -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=

24
internal/daemon/api.go Normal file
View file

@ -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)
}

View file

@ -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)
}
}

12
main.go
View file

@ -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() {