feat: add stub daemon command + api
This commit is contained in:
parent
44efd478a7
commit
d184b2da77
5 changed files with 52 additions and 0 deletions
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module courgette
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
forge.karnov.club/marc/http-api-kit v0.0.1
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible
|
github.com/gofrs/uuid v4.4.0+incompatible
|
||||||
github.com/spf13/cobra v1.8.1
|
github.com/spf13/cobra v1.8.1
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
|
|
2
go.sum
2
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/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 h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
|
|
24
internal/daemon/api.go
Normal file
24
internal/daemon/api.go
Normal 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)
|
||||||
|
}
|
13
internal/daemon/api_test.go
Normal file
13
internal/daemon/api_test.go
Normal 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
12
main.go
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
commands "courgette/internal/commands"
|
commands "courgette/internal/commands"
|
||||||
|
daemon "courgette/internal/daemon"
|
||||||
logger "courgette/internal/logging"
|
logger "courgette/internal/logging"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
"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{
|
var knownCommands = []*cobra.Command{
|
||||||
execute,
|
execute,
|
||||||
validate,
|
validate,
|
||||||
|
daemonCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in a new issue