Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ client/build/bin
client/node_modules
client/frontend/dist
tmp
node_modules/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "app/spilothq/googleapis"]
path = app/spilothq/googleapis
url = https://github.com/googleapis/googleapis
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
gen:
protoc --go_out=./internal --go-grpc_out=./internal internal/proto/*.proto;
protoc --go_out=. --go-grpc_out=. app/spilothq/proto/*.proto;

genapi:
protoc --go_out=app/spilothq/api --go-grpc_out=app/spilothq/api app/spilothq/api/v1/*.proto;

# gen:
# protoc --proto_path=internal/proto internal/proto/*.proto --go_out=plugins=grpc:pb
Expand All @@ -14,4 +16,6 @@ devhq:

devadmin:
air -c ./zarf/air/admin.toml


startui:
cd ./app/spilotui && wails dev
62 changes: 62 additions & 0 deletions api/spilot/driver/grpc/grpc_driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package driver

import (
"context"
"fmt"
"net"

apiv1 "github.com/aforamitdev/server-pilot/app/spilothq/gen/proto/api/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

type GrpcDriver struct {
ctx context.Context
conn *grpc.ClientConn
}

func NewGrpcDriver() *GrpcDriver {
return &GrpcDriver{}
}

func (g *GrpcDriver) Startup(ctx context.Context) {
g.ctx = ctx
}

func (g *GrpcDriver) ConnectServer(ip net.IP, port string) (success bool, err error) {
conn, err := grpc.NewClient(fmt.Sprintf(`%s:%s`, ip, port), grpc.WithTransportCredentials(insecure.NewCredentials()))

if err != nil {
fmt.Println(err)
return false, err
}
fmt.Println(conn.GetState())

g.conn = conn

s := apiv1.NewSystemServicesClient(conn)

req := apiv1.GetStatusRequest{}
res, err := s.GetStatus(g.ctx, &req)
if err != nil {
fmt.Println(err, "Errr")
}
fmt.Println(res)

return true, nil

}

func (g *GrpcDriver) GetServerStatus(ctx context.Context) apiv1.GetStatusResponse {

s := apiv1.NewSystemServicesClient(g.conn)

req := apiv1.GetStatusRequest{}
res, err := s.GetStatus(ctx, &req)
if err != nil {
fmt.Println(err)
}

return *res

}
43 changes: 37 additions & 6 deletions api/spilot/spilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"context"
"fmt"
"os"

apiv1 "github.com/aforamitdev/server-pilot/app/spilothq/gen/proto/api/v1"
"github.com/aforamitdev/server-pilot/pkg/logger"
"github.com/aforamitdev/server-pilot/pkg/web"
"google.golang.org/grpc"
Expand All @@ -24,21 +26,31 @@ func main() {
log = logger.NewWithEvents(os.Stdout, logger.LevelInfo, "SPILOT-CLIENT", traceIDFn, events)

ctx := context.Background()
conn, err := grpc.NewClient("localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
fmt.Println(conn)
if err != nil {
log.Error(ctx, "startup", "msg", err)
}

defer conn.Close()

// client := pb.NewInformerClient(conn)
c := apiv1.NewLogServiceClient(conn)

// ctx, cancel := context.WithTimeout(context.Background(), time.Second)
if err != nil {
fmt.Println(err)
}
r, err := c.GetLogs(ctx, &apiv1.LogRequest{})

// defer cancel()
if err != nil {
fmt.Println(err)
}

// r, err := client.GetSystem(ctx, &pb.SystemRequest{})
logchan := logstream(r)
for res := range logchan {
fmt.Println(res)
}

// stream, err := client.GetLogs(context.Background(), &pb.LogRequest{})
// r, err := client.

// fmt.Println(r.Name)

Expand All @@ -60,3 +72,22 @@ func main() {
// }

}

// ServerStreamingClient[apiv1.LogResponse]
func logstream(r grpc.ServerStreamingClient[apiv1.LogResponse]) chan *apiv1.LogResponse {
logchan := make(chan *apiv1.LogResponse)

go func() {
for {
resp, err := r.Recv()
if err != nil {
fmt.Println(err)
}
fmt.Println(resp)
logchan <- resp
}
}()

return logchan

}
1 change: 1 addition & 0 deletions api/spilot/stream.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
46 changes: 46 additions & 0 deletions app/spilothq/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# version: v2
# managed:
# enabled: true
# override:
# - file_option: go_package_prefix
# value: github.com/bufbuild/buf-tour/gen
# plugins:
# - remote: buf.build/protocolbuffers/go
# out: api/gen/proto
# opt: paths=source_relative
# - remote: buf.build/connectrpc/go
# out: api/gen/proto
# opt: paths=source_relative
# inputs:
# - directory: proto

version: v2
managed:
enabled: true
disable:
- file_option: go_package
module: buf.build/googleapis/googleapis
override:
- file_option: go_package_prefix
value: github.com/aforamitdev/server-pilot/app/spilothq/proto
plugins:
- local: protoc-gen-go
out: gen
opt: paths=source_relative
- remote: buf.build/grpc/go
out: gen
opt: paths=source_relative
- remote: buf.build/grpc-ecosystem/openapiv2
out: gen
opt: output_format=yaml,allow_merge=true

- remote: buf.build/community/stephenh-ts-proto
out: ../spilotui/frontend/src/app/types
opt:
- env=browser
- useOptionals=messages
- outputServices=generic-definitions
- outputJsonMethods=false
- useExactTypes=false
- esModuleInterop=true
- stringEnums=true
16 changes: 16 additions & 0 deletions app/spilothq/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# For details on buf.yaml configuration, visit https://buf.build/docs/configuration/v2/buf-yaml
version: v2
# name: buf.build/aforamitdev/server-pilot
modules:
- path: proto/api/v1/
- path: proto/api/store/

deps:
- buf.build/googleapis/googleapis
- buf.build/grpc-ecosystem/grpc-gateway
lint:
use:
- STANDARD
breaking:
use:
- FILE
42 changes: 42 additions & 0 deletions app/spilothq/gen/apidocs.swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
swagger: "2.0"
info:
title: log_service.proto
version: version not set
tags:
- name: LogService
- name: SystemServices
consumes:
- application/json
produces:
- application/json
paths: {}
definitions:
protobufAny:
type: object
properties:
'@type':
type: string
additionalProperties: {}
rpcStatus:
type: object
properties:
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
$ref: '#/definitions/protobufAny'
v1GetStatusResponse:
type: object
properties:
system:
type: string
v1LogResponse:
type: object
properties:
log:
type: string
Loading