diff --git a/.gitignore b/.gitignore index 3e110c1..23fc5df 100644 --- a/.gitignore +++ b/.gitignore @@ -31,4 +31,5 @@ assets *.mp4 # Nix -result \ No newline at end of file +result +api diff --git a/Makefile b/Makefile index 3e63734..fa09331 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ DEST_DIR = /opt/komputer ARCH = $(shell uname -m) OUTPUT_DIR=./build +PROTOBUF_API_DEST=./api ifeq ($(ARCH), x86_64) GOARCH="amd64" @@ -8,26 +9,41 @@ else GOARCH="arm64" endif -dev: +.PHONY: test clean + +dev: proto CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) go build -tags dev -o $(OUTPUT_DIR)/komputer ./cmd/komputer/main.go -prod: + +prod: proto CGO_ENABLED=1 GOOS=linux GOARCH=$(GOARCH) go build -o $(OUTPUT_DIR)/komputer ./cmd/komputer/main.go -test: - go test -race ./bot/... +tui: proto + go build -o $(OUTPUT_DIR)/tui ./tui/cmd/main.go + +protobuf: cleanProto + mkdir -p $(PROTOBUF_API_DEST) + protoc --go_out=. ./proto/* + +test: proto + go test -race ./... install: prod test - mkdir -p $(DEST_DIR) - cp -r assets $(DEST_DIR) - cp $(OUTPUT_DIR)/komputer $(DEST_DIR) + mkdir -p $(PROTOBUF_API_DEST) + cp -r assets $(PROTOBUF_API_DEST) + cp $(OUTPUT_DIR)/komputer $(PROTOBUF_API_DEST) uninstall: -ifneq ("$(wildcard $(DEST_DIR))", "") - rm -r $(DEST_DIR) +ifneq ("$(wildcard $(PROTOBUF_API_DEST))", "") + rm -r $(PROTOBUF_API_DEST) endif -clean: +clean: cleanProto ifneq ("$(wildcard $(OUTPUT_DIR))", "") - rm -r build + rm -r $(OUTPUT_DIR) +endif + +cleanProto: +ifneq ("$(wildcard $(PROTOBUF_API_DEST))", "") + rm -r $(PROTOBUF_API_DEST) endif diff --git a/go.mod b/go.mod index abed33d..1d54143 100644 --- a/go.mod +++ b/go.mod @@ -27,4 +27,7 @@ require ( golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect + google.golang.org/grpc v1.64.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index 4f48497..3010db3 100644 --- a/go.sum +++ b/go.sum @@ -66,5 +66,11 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32 h1:/S1gOotFo2sADAIdSGk1sDq1VxetoCWr6f5nxOG0dpY= layeh.com/gopus v0.0.0-20210501142526-1ee02d434e32/go.mod h1:yDtyzWZDFCVnva8NGtg38eH2Ns4J0D/6hD+MMeUGdF0= diff --git a/nixos/shell.nix b/nixos/shell.nix index 397bb85..876d2a4 100644 --- a/nixos/shell.nix +++ b/nixos/shell.nix @@ -1,14 +1,14 @@ -{ mkShell, go, gopls, ffmpeg, nixfmt-classic, ... }: mkShell { +{ mkShell, go, gopls, ffmpeg, nixfmt-classic, protoc-gen-go, protobuf, protoc-gen-go-grpc, ... }: mkShell { hardeningDisable = [ "all" ]; - buildInputs = [ - # Go + nativeBuildInputs = [ go + protobuf + ]; + buildInputs = [ gopls - - # Runtime dependecies + protoc-gen-go-grpc + protoc-gen-go ffmpeg - - # Nixpkgs nixfmt-classic ]; diff --git a/protobuf/admin.proto b/proto/admin.proto similarity index 92% rename from protobuf/admin.proto rename to proto/admin.proto index 78e7845..a9263ff 100644 --- a/protobuf/admin.proto +++ b/proto/admin.proto @@ -1,7 +1,8 @@ syntax = "proto3"; +option go_package = "./api"; import "google/protobuf/empty.proto"; -import "protobuf/request.proto"; +import "proto/request.proto"; package komputer; enum Privileges { diff --git a/protobuf/audio.proto b/proto/audio.proto similarity index 91% rename from protobuf/audio.proto rename to proto/audio.proto index fc485e3..0d82ac0 100644 --- a/protobuf/audio.proto +++ b/proto/audio.proto @@ -1,7 +1,8 @@ syntax = "proto3"; +option go_package = "./api"; import "google/protobuf/empty.proto"; -import "protobuf/request.proto"; +import "proto/request.proto"; package komputer; enum FileFormat { diff --git a/protobuf/joke.proto b/proto/joke.proto similarity index 91% rename from protobuf/joke.proto rename to proto/joke.proto index c1eb77d..cb7ec21 100644 --- a/protobuf/joke.proto +++ b/proto/joke.proto @@ -1,7 +1,8 @@ syntax = "proto3"; +option go_package = "./api"; import "google/protobuf/empty.proto"; -import "protobuf/request.proto"; +import "proto/request.proto"; package komputer; enum Type { diff --git a/protobuf/logs.proto b/proto/logs.proto similarity index 95% rename from protobuf/logs.proto rename to proto/logs.proto index 59fe073..c4a8442 100644 --- a/protobuf/logs.proto +++ b/proto/logs.proto @@ -1,5 +1,6 @@ syntax = "proto3"; +option go_package = "./api"; import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; package komputer; diff --git a/protobuf/options.proto b/proto/options.proto similarity index 93% rename from protobuf/options.proto rename to proto/options.proto index 7a972a9..9193e2b 100644 --- a/protobuf/options.proto +++ b/proto/options.proto @@ -1,5 +1,6 @@ syntax = "proto3"; +option go_package = "./api"; package komputer; enum Features { diff --git a/protobuf/request.proto b/proto/request.proto similarity index 92% rename from protobuf/request.proto rename to proto/request.proto index 83bafce..86abcbd 100644 --- a/protobuf/request.proto +++ b/proto/request.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -import "google/protobuf/empty.proto"; +option go_package = "./api"; package komputer; message Pagination {