feat: add ax serve command with JSON API backed by NodeService

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-01 13:04:29 +02:00
parent 9e5194893e
commit 3dfc46c3ff
5 changed files with 256 additions and 2 deletions

30
cmd/serve.go Normal file
View File

@@ -0,0 +1,30 @@
package cmd
import (
"axolotl/serve"
"axolotl/service"
"fmt"
"net/http"
"os"
"github.com/spf13/cobra"
)
var serveCmd = &cobra.Command{
Use: "serve",
Short: "Start the JSON API server",
Run: func(cmd *cobra.Command, args []string) {
sc := cfg.GetServerConfig()
addr := fmt.Sprintf("%s:%d", sc.Host, sc.Port)
handler := serve.New(service.GetNodeServiceForUser)
fmt.Fprintf(os.Stdout, "listening on %s\n", addr)
if err := http.ListenAndServe(addr, handler); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
},
}
func init() {
rootCmd.AddCommand(serveCmd)
}