Skip to content

Commit

Permalink
feat(grpc): created makefile tasks for generate gRPC API
Browse files Browse the repository at this point in the history
  • Loading branch information
Wittano committed May 15, 2024
1 parent 38f4704 commit f3352be
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ assets
*.mp4

# Nix
result
result
api
38 changes: 27 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
DEST_DIR = /opt/komputer
ARCH = $(shell uname -m)
OUTPUT_DIR=./build
PROTOBUF_API_DEST=./api

ifeq ($(ARCH), x86_64)
GOARCH="amd64"
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
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
14 changes: 7 additions & 7 deletions nixos/shell.nix
Original file line number Diff line number Diff line change
@@ -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
];

Expand Down
3 changes: 2 additions & 1 deletion protobuf/admin.proto → proto/admin.proto
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion protobuf/audio.proto → proto/audio.proto
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion protobuf/joke.proto → proto/joke.proto
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 1 addition & 0 deletions protobuf/logs.proto → proto/logs.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";

option go_package = "./api";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
package komputer;
Expand Down
1 change: 1 addition & 0 deletions protobuf/options.proto → proto/options.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
syntax = "proto3";

option go_package = "./api";
package komputer;

enum Features {
Expand Down
2 changes: 1 addition & 1 deletion protobuf/request.proto → proto/request.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
syntax = "proto3";

import "google/protobuf/empty.proto";
option go_package = "./api";
package komputer;

message Pagination {
Expand Down

0 comments on commit f3352be

Please sign in to comment.