Move server things into server folder, add basic admin program for interacting with the admin api

This commit is contained in:
batteredbunny 2025-02-01 19:38:58 +02:00
parent e1ab7189f4
commit cce62f6f1a
23 changed files with 90 additions and 1 deletions

23
admincli/action.go Normal file
View file

@ -0,0 +1,23 @@
package admincli
import (
"fmt"
"net/http"
)
func PlayRandomAction(c Command) {
println("Playing random video")
http.Get(fmt.Sprintf("http://localhost:%d/api/random", c.Port))
}
func PlayAction(c Command) {
println("Play action is not yet implemented")
}
func StopAction(c Command) {
println("Stop action is not yet implemented")
}
func NowPlayingAction(c Command) {
println("Now playing action is not yet implemented")
}

14
admincli/build.nix Normal file
View file

@ -0,0 +1,14 @@
{ buildGoModule
,
}:
buildGoModule {
src = ./.;
name = "admincli";
vendorHash = null;
ldflags = [
"-s"
"-w"
];
}

3
admincli/go.mod Normal file
View file

@ -0,0 +1,3 @@
module admincli
go 1.23.4

42
admincli/main.go Normal file
View file

@ -0,0 +1,42 @@
package admincli
import (
"flag"
"fmt"
"slices"
"strings"
"maps"
)
var actionMap = map[string]func(c Command){
"play-random": PlayRandomAction,
"play": PlayAction,
"stop": StopAction,
"now-playing": NowPlayingAction,
}
func getActionNames() string {
return strings.Join(slices.Collect(maps.Keys(actionMap)), ", ")
}
type Command struct {
Action string
Args []string
Port int
}
func main() {
var c Command
flag.StringVar(&c.Action, "action", "none", fmt.Sprintf("Available actions: %s", getActionNames()))
flag.IntVar(&c.Port, "port", 3001, "The private admin api port")
flag.Parse()
f, exists := actionMap[c.Action]
if !exists {
println("Unknown action:", c.Action)
return
}
f(c)
}

View file

@ -35,7 +35,9 @@
}; };
packages = { packages = {
default = callPackage ./build.nix { }; default = callPackage ./server/build.nix { };
livestream-server = callPackage ./server/build.nix { };
livestream-admincli = callPackage ./admincli/build.nix { };
docker = callPackage ./docker.nix { docker = callPackage ./docker.nix {
default = dockerCallPackage ./build.nix { }; default = dockerCallPackage ./build.nix { };
inherit nix2container; inherit nix2container;

5
go.work Normal file
View file

@ -0,0 +1,5 @@
go 1.23.4
use ./admincli
use ./server