Init commit

This commit is contained in:
2026-08-29 09:08:22 +05:00
commit eaa9a7bef2
21 changed files with 2738 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
bin/
node_modules/
web/dist/
.DS_Store
+29
View File
@@ -0,0 +1,29 @@
.PHONY: proto web server dev test
proto: ## Regenerate Go + TS code from proto
PATH="$(shell go env GOPATH)/bin:$$PATH" protoc \
--proto_path=proto \
--go_out=. --go_opt=module=pwa-homelab-mon \
--connect-go_out=. --connect-go_opt=module=pwa-homelab-mon \
--plugin=protoc-gen-es=web/node_modules/.bin/protoc-gen-es \
--es_out=web/src/gen --es_opt=target=ts \
proto/homelab/v1/homelab.proto
web: ## Build frontend into web/dist
cd web && pnpm install --frozen-lockfile && pnpm build
server: ## Build Go binary
go build -o bin/server ./server
dev: ## Dev: Go server on :8080 + Vite on :5173 (use http://localhost:5173)
go run ./server & cd web && pnpm dev
test: ## Smoke-test the RPC endpoints
@go build -o bin/server ./server
@./bin/server & sleep 1; \
for i in 1 2; do \
curl -sf -X POST localhost:8080/homelab.v1.HomelabService/IncrementCounter -H 'Content-Type: application/json' -d '{}' | grep -q "\"value\":\"$$i\"" || exit 1; \
done; \
curl -sf -X POST localhost:8080/homelab.v1.HomelabService/SayHello -H 'Content-Type: application/json' -d '{"name":"Pony"}' | grep -q 'Hello, Pony!' || exit 1; \
curl -sf -X POST localhost:8080/homelab.v1.HomelabService/GetLuckyNumber -H 'Content-Type: application/json' -d '{}' | grep -q '"number"' || exit 1; \
kill %1; echo OK
+350
View File
@@ -0,0 +1,350 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.12
// protoc v7.35.1
// source: homelab/v1/homelab.proto
package homelabv1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
unsafe "unsafe"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type GetLuckyNumberRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetLuckyNumberRequest) Reset() {
*x = GetLuckyNumberRequest{}
mi := &file_homelab_v1_homelab_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetLuckyNumberRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetLuckyNumberRequest) ProtoMessage() {}
func (x *GetLuckyNumberRequest) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetLuckyNumberRequest.ProtoReflect.Descriptor instead.
func (*GetLuckyNumberRequest) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{0}
}
type GetLuckyNumberResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Number int64 `protobuf:"varint,1,opt,name=number,proto3" json:"number,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetLuckyNumberResponse) Reset() {
*x = GetLuckyNumberResponse{}
mi := &file_homelab_v1_homelab_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetLuckyNumberResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetLuckyNumberResponse) ProtoMessage() {}
func (x *GetLuckyNumberResponse) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetLuckyNumberResponse.ProtoReflect.Descriptor instead.
func (*GetLuckyNumberResponse) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{1}
}
func (x *GetLuckyNumberResponse) GetNumber() int64 {
if x != nil {
return x.Number
}
return 0
}
type IncrementCounterRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *IncrementCounterRequest) Reset() {
*x = IncrementCounterRequest{}
mi := &file_homelab_v1_homelab_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *IncrementCounterRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*IncrementCounterRequest) ProtoMessage() {}
func (x *IncrementCounterRequest) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use IncrementCounterRequest.ProtoReflect.Descriptor instead.
func (*IncrementCounterRequest) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{2}
}
type IncrementCounterResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Value int64 `protobuf:"varint,1,opt,name=value,proto3" json:"value,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *IncrementCounterResponse) Reset() {
*x = IncrementCounterResponse{}
mi := &file_homelab_v1_homelab_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *IncrementCounterResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*IncrementCounterResponse) ProtoMessage() {}
func (x *IncrementCounterResponse) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use IncrementCounterResponse.ProtoReflect.Descriptor instead.
func (*IncrementCounterResponse) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{3}
}
func (x *IncrementCounterResponse) GetValue() int64 {
if x != nil {
return x.Value
}
return 0
}
type SayHelloRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SayHelloRequest) Reset() {
*x = SayHelloRequest{}
mi := &file_homelab_v1_homelab_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SayHelloRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SayHelloRequest) ProtoMessage() {}
func (x *SayHelloRequest) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SayHelloRequest.ProtoReflect.Descriptor instead.
func (*SayHelloRequest) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{4}
}
func (x *SayHelloRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
type SayHelloResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Greeting string `protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *SayHelloResponse) Reset() {
*x = SayHelloResponse{}
mi := &file_homelab_v1_homelab_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *SayHelloResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SayHelloResponse) ProtoMessage() {}
func (x *SayHelloResponse) ProtoReflect() protoreflect.Message {
mi := &file_homelab_v1_homelab_proto_msgTypes[5]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SayHelloResponse.ProtoReflect.Descriptor instead.
func (*SayHelloResponse) Descriptor() ([]byte, []int) {
return file_homelab_v1_homelab_proto_rawDescGZIP(), []int{5}
}
func (x *SayHelloResponse) GetGreeting() string {
if x != nil {
return x.Greeting
}
return ""
}
var File_homelab_v1_homelab_proto protoreflect.FileDescriptor
const file_homelab_v1_homelab_proto_rawDesc = "" +
"\n" +
"\x18homelab/v1/homelab.proto\x12\n" +
"homelab.v1\"\x17\n" +
"\x15GetLuckyNumberRequest\"0\n" +
"\x16GetLuckyNumberResponse\x12\x16\n" +
"\x06number\x18\x01 \x01(\x03R\x06number\"\x19\n" +
"\x17IncrementCounterRequest\"0\n" +
"\x18IncrementCounterResponse\x12\x14\n" +
"\x05value\x18\x01 \x01(\x03R\x05value\"%\n" +
"\x0fSayHelloRequest\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\".\n" +
"\x10SayHelloResponse\x12\x1a\n" +
"\bgreeting\x18\x01 \x01(\tR\bgreeting2\x8f\x02\n" +
"\x0eHomelabService\x12W\n" +
"\x0eGetLuckyNumber\x12!.homelab.v1.GetLuckyNumberRequest\x1a\".homelab.v1.GetLuckyNumberResponse\x12]\n" +
"\x10IncrementCounter\x12#.homelab.v1.IncrementCounterRequest\x1a$.homelab.v1.IncrementCounterResponse\x12E\n" +
"\bSayHello\x12\x1b.homelab.v1.SayHelloRequest\x1a\x1c.homelab.v1.SayHelloResponseB*Z(pwa-homelab-mon/gen/homelab/v1;homelabv1b\x06proto3"
var (
file_homelab_v1_homelab_proto_rawDescOnce sync.Once
file_homelab_v1_homelab_proto_rawDescData []byte
)
func file_homelab_v1_homelab_proto_rawDescGZIP() []byte {
file_homelab_v1_homelab_proto_rawDescOnce.Do(func() {
file_homelab_v1_homelab_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_homelab_v1_homelab_proto_rawDesc), len(file_homelab_v1_homelab_proto_rawDesc)))
})
return file_homelab_v1_homelab_proto_rawDescData
}
var file_homelab_v1_homelab_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_homelab_v1_homelab_proto_goTypes = []any{
(*GetLuckyNumberRequest)(nil), // 0: homelab.v1.GetLuckyNumberRequest
(*GetLuckyNumberResponse)(nil), // 1: homelab.v1.GetLuckyNumberResponse
(*IncrementCounterRequest)(nil), // 2: homelab.v1.IncrementCounterRequest
(*IncrementCounterResponse)(nil), // 3: homelab.v1.IncrementCounterResponse
(*SayHelloRequest)(nil), // 4: homelab.v1.SayHelloRequest
(*SayHelloResponse)(nil), // 5: homelab.v1.SayHelloResponse
}
var file_homelab_v1_homelab_proto_depIdxs = []int32{
0, // 0: homelab.v1.HomelabService.GetLuckyNumber:input_type -> homelab.v1.GetLuckyNumberRequest
2, // 1: homelab.v1.HomelabService.IncrementCounter:input_type -> homelab.v1.IncrementCounterRequest
4, // 2: homelab.v1.HomelabService.SayHello:input_type -> homelab.v1.SayHelloRequest
1, // 3: homelab.v1.HomelabService.GetLuckyNumber:output_type -> homelab.v1.GetLuckyNumberResponse
3, // 4: homelab.v1.HomelabService.IncrementCounter:output_type -> homelab.v1.IncrementCounterResponse
5, // 5: homelab.v1.HomelabService.SayHello:output_type -> homelab.v1.SayHelloResponse
3, // [3:6] is the sub-list for method output_type
0, // [0:3] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_homelab_v1_homelab_proto_init() }
func file_homelab_v1_homelab_proto_init() {
if File_homelab_v1_homelab_proto != nil {
return
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_homelab_v1_homelab_proto_rawDesc), len(file_homelab_v1_homelab_proto_rawDesc)),
NumEnums: 0,
NumMessages: 6,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_homelab_v1_homelab_proto_goTypes,
DependencyIndexes: file_homelab_v1_homelab_proto_depIdxs,
MessageInfos: file_homelab_v1_homelab_proto_msgTypes,
}.Build()
File_homelab_v1_homelab_proto = out.File
file_homelab_v1_homelab_proto_goTypes = nil
file_homelab_v1_homelab_proto_depIdxs = nil
}
@@ -0,0 +1,166 @@
// Code generated by protoc-gen-connect-go. DO NOT EDIT.
//
// Source: homelab/v1/homelab.proto
package homelabv1connect
import (
connect "connectrpc.com/connect"
context "context"
errors "errors"
http "net/http"
v1 "pwa-homelab-mon/gen/homelab/v1"
strings "strings"
)
// This is a compile-time assertion to ensure that this generated file and the connect package are
// compatible. If you get a compiler error that this constant is not defined, this code was
// generated with a version of connect newer than the one compiled into your binary. You can fix the
// problem by either regenerating this code with an older version of connect or updating the connect
// version compiled into your binary.
const _ = connect.IsAtLeastVersion1_13_0
const (
// HomelabServiceName is the fully-qualified name of the HomelabService service.
HomelabServiceName = "homelab.v1.HomelabService"
)
// These constants are the fully-qualified names of the RPCs defined in this package. They're
// exposed at runtime as Spec.Procedure and as the final two segments of the HTTP route.
//
// Note that these are different from the fully-qualified method names used by
// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to
// reflection-formatted method names, remove the leading slash and convert the remaining slash to a
// period.
const (
// HomelabServiceGetLuckyNumberProcedure is the fully-qualified name of the HomelabService's
// GetLuckyNumber RPC.
HomelabServiceGetLuckyNumberProcedure = "/homelab.v1.HomelabService/GetLuckyNumber"
// HomelabServiceIncrementCounterProcedure is the fully-qualified name of the HomelabService's
// IncrementCounter RPC.
HomelabServiceIncrementCounterProcedure = "/homelab.v1.HomelabService/IncrementCounter"
// HomelabServiceSayHelloProcedure is the fully-qualified name of the HomelabService's SayHello RPC.
HomelabServiceSayHelloProcedure = "/homelab.v1.HomelabService/SayHello"
)
// HomelabServiceClient is a client for the homelab.v1.HomelabService service.
type HomelabServiceClient interface {
GetLuckyNumber(context.Context, *connect.Request[v1.GetLuckyNumberRequest]) (*connect.Response[v1.GetLuckyNumberResponse], error)
IncrementCounter(context.Context, *connect.Request[v1.IncrementCounterRequest]) (*connect.Response[v1.IncrementCounterResponse], error)
SayHello(context.Context, *connect.Request[v1.SayHelloRequest]) (*connect.Response[v1.SayHelloResponse], error)
}
// NewHomelabServiceClient constructs a client for the homelab.v1.HomelabService service. By
// default, it uses the Connect protocol with the binary Protobuf Codec, asks for gzipped responses,
// and sends uncompressed requests. To use the gRPC or gRPC-Web protocols, supply the
// connect.WithGRPC() or connect.WithGRPCWeb() options.
//
// The URL supplied here should be the base URL for the Connect or gRPC server (for example,
// http://api.acme.com or https://acme.com/grpc).
func NewHomelabServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) HomelabServiceClient {
baseURL = strings.TrimRight(baseURL, "/")
homelabServiceMethods := v1.File_homelab_v1_homelab_proto.Services().ByName("HomelabService").Methods()
return &homelabServiceClient{
getLuckyNumber: connect.NewClient[v1.GetLuckyNumberRequest, v1.GetLuckyNumberResponse](
httpClient,
baseURL+HomelabServiceGetLuckyNumberProcedure,
connect.WithSchema(homelabServiceMethods.ByName("GetLuckyNumber")),
connect.WithClientOptions(opts...),
),
incrementCounter: connect.NewClient[v1.IncrementCounterRequest, v1.IncrementCounterResponse](
httpClient,
baseURL+HomelabServiceIncrementCounterProcedure,
connect.WithSchema(homelabServiceMethods.ByName("IncrementCounter")),
connect.WithClientOptions(opts...),
),
sayHello: connect.NewClient[v1.SayHelloRequest, v1.SayHelloResponse](
httpClient,
baseURL+HomelabServiceSayHelloProcedure,
connect.WithSchema(homelabServiceMethods.ByName("SayHello")),
connect.WithClientOptions(opts...),
),
}
}
// homelabServiceClient implements HomelabServiceClient.
type homelabServiceClient struct {
getLuckyNumber *connect.Client[v1.GetLuckyNumberRequest, v1.GetLuckyNumberResponse]
incrementCounter *connect.Client[v1.IncrementCounterRequest, v1.IncrementCounterResponse]
sayHello *connect.Client[v1.SayHelloRequest, v1.SayHelloResponse]
}
// GetLuckyNumber calls homelab.v1.HomelabService.GetLuckyNumber.
func (c *homelabServiceClient) GetLuckyNumber(ctx context.Context, req *connect.Request[v1.GetLuckyNumberRequest]) (*connect.Response[v1.GetLuckyNumberResponse], error) {
return c.getLuckyNumber.CallUnary(ctx, req)
}
// IncrementCounter calls homelab.v1.HomelabService.IncrementCounter.
func (c *homelabServiceClient) IncrementCounter(ctx context.Context, req *connect.Request[v1.IncrementCounterRequest]) (*connect.Response[v1.IncrementCounterResponse], error) {
return c.incrementCounter.CallUnary(ctx, req)
}
// SayHello calls homelab.v1.HomelabService.SayHello.
func (c *homelabServiceClient) SayHello(ctx context.Context, req *connect.Request[v1.SayHelloRequest]) (*connect.Response[v1.SayHelloResponse], error) {
return c.sayHello.CallUnary(ctx, req)
}
// HomelabServiceHandler is an implementation of the homelab.v1.HomelabService service.
type HomelabServiceHandler interface {
GetLuckyNumber(context.Context, *connect.Request[v1.GetLuckyNumberRequest]) (*connect.Response[v1.GetLuckyNumberResponse], error)
IncrementCounter(context.Context, *connect.Request[v1.IncrementCounterRequest]) (*connect.Response[v1.IncrementCounterResponse], error)
SayHello(context.Context, *connect.Request[v1.SayHelloRequest]) (*connect.Response[v1.SayHelloResponse], error)
}
// NewHomelabServiceHandler builds an HTTP handler from the service implementation. It returns the
// path on which to mount the handler and the handler itself.
//
// By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf
// and JSON codecs. They also support gzip compression.
func NewHomelabServiceHandler(svc HomelabServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) {
homelabServiceMethods := v1.File_homelab_v1_homelab_proto.Services().ByName("HomelabService").Methods()
homelabServiceGetLuckyNumberHandler := connect.NewUnaryHandler(
HomelabServiceGetLuckyNumberProcedure,
svc.GetLuckyNumber,
connect.WithSchema(homelabServiceMethods.ByName("GetLuckyNumber")),
connect.WithHandlerOptions(opts...),
)
homelabServiceIncrementCounterHandler := connect.NewUnaryHandler(
HomelabServiceIncrementCounterProcedure,
svc.IncrementCounter,
connect.WithSchema(homelabServiceMethods.ByName("IncrementCounter")),
connect.WithHandlerOptions(opts...),
)
homelabServiceSayHelloHandler := connect.NewUnaryHandler(
HomelabServiceSayHelloProcedure,
svc.SayHello,
connect.WithSchema(homelabServiceMethods.ByName("SayHello")),
connect.WithHandlerOptions(opts...),
)
return "/homelab.v1.HomelabService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case HomelabServiceGetLuckyNumberProcedure:
homelabServiceGetLuckyNumberHandler.ServeHTTP(w, r)
case HomelabServiceIncrementCounterProcedure:
homelabServiceIncrementCounterHandler.ServeHTTP(w, r)
case HomelabServiceSayHelloProcedure:
homelabServiceSayHelloHandler.ServeHTTP(w, r)
default:
http.NotFound(w, r)
}
})
}
// UnimplementedHomelabServiceHandler returns CodeUnimplemented from all methods.
type UnimplementedHomelabServiceHandler struct{}
func (UnimplementedHomelabServiceHandler) GetLuckyNumber(context.Context, *connect.Request[v1.GetLuckyNumberRequest]) (*connect.Response[v1.GetLuckyNumberResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("homelab.v1.HomelabService.GetLuckyNumber is not implemented"))
}
func (UnimplementedHomelabServiceHandler) IncrementCounter(context.Context, *connect.Request[v1.IncrementCounterRequest]) (*connect.Response[v1.IncrementCounterResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("homelab.v1.HomelabService.IncrementCounter is not implemented"))
}
func (UnimplementedHomelabServiceHandler) SayHello(context.Context, *connect.Request[v1.SayHelloRequest]) (*connect.Response[v1.SayHelloResponse], error) {
return nil, connect.NewError(connect.CodeUnimplemented, errors.New("homelab.v1.HomelabService.SayHello is not implemented"))
}
+22
View File
@@ -0,0 +1,22 @@
module pwa-homelab-mon
go 1.26.5
require (
connectrpc.com/connect v1.20.0
github.com/labstack/echo/v4 v4.15.4
google.golang.org/protobuf v1.36.12
)
require (
github.com/labstack/gommon v0.5.0 // indirect
github.com/mattn/go-colorable v0.1.15 // indirect
github.com/mattn/go-isatty v0.0.22 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
golang.org/x/crypto v0.53.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
golang.org/x/time v0.15.0 // indirect
)
+36
View File
@@ -0,0 +1,36 @@
connectrpc.com/connect v1.20.0 h1:6TNDAB+WeNd2uolWNlYczB5E0KNNaVMNUEx8JEUsPmQ=
connectrpc.com/connect v1.20.0/go.mod h1:A2ygJrukXwWy32vkCAAHNVguZrqZ+jeZ9rGRnGR4dN4=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/labstack/echo/v4 v4.15.4 h1:DL45vVYa+BWE+XuW+zZNd9H0YEdZ80UAWJGcTVW4EVs=
github.com/labstack/echo/v4 v4.15.4/go.mod h1:CuMetKIRwsuO/qlAgMq+KTAalwGoB/h4tC+yPdrTj1g=
github.com/labstack/gommon v0.5.0 h1:6VSQ2NOzsnEJ5W6+84E0RbcaDDmgB6NIAzWCczTEe6c=
github.com/labstack/gommon v0.5.0/go.mod h1:Rzlg7HHy1maLfzBYGg9NZcVuz1sA68HHhLjhcEllYE0=
github.com/mattn/go-colorable v0.1.15 h1:+u9SLTRGnXv73cEsnsmoZBom+dMU88B2M0aDcWy0/jY=
github.com/mattn/go-colorable v0.1.15/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.22 h1:j8l17JJ9i6VGPUFUYoTUKPSgKe/83EYU2zBC7YNKMw4=
github.com/mattn/go-isatty v0.0.22/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc=
google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+28
View File
@@ -0,0 +1,28 @@
syntax = "proto3";
package homelab.v1;
option go_package = "pwa-homelab-mon/gen/homelab/v1;homelabv1";
message GetLuckyNumberRequest {}
message GetLuckyNumberResponse {
int64 number = 1;
}
message IncrementCounterRequest {}
message IncrementCounterResponse {
int64 value = 1;
}
message SayHelloRequest {
string name = 1;
}
message SayHelloResponse {
string greeting = 1;
}
service HomelabService {
rpc GetLuckyNumber(GetLuckyNumberRequest) returns (GetLuckyNumberResponse);
rpc IncrementCounter(IncrementCounterRequest) returns (IncrementCounterResponse);
rpc SayHello(SayHelloRequest) returns (SayHelloResponse);
}
+66
View File
@@ -0,0 +1,66 @@
package main
import (
"context"
"math/rand/v2"
"net/http"
"os"
"sync/atomic"
"connectrpc.com/connect"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
homelabv1 "pwa-homelab-mon/gen/homelab/v1"
"pwa-homelab-mon/gen/homelab/v1/homelabv1connect"
)
type server struct {
lucky int64
counter atomic.Int64
}
func (s *server) GetLuckyNumber(context.Context, *connect.Request[homelabv1.GetLuckyNumberRequest]) (*connect.Response[homelabv1.GetLuckyNumberResponse], error) {
return connect.NewResponse(&homelabv1.GetLuckyNumberResponse{Number: s.lucky}), nil
}
func (s *server) IncrementCounter(context.Context, *connect.Request[homelabv1.IncrementCounterRequest]) (*connect.Response[homelabv1.IncrementCounterResponse], error) {
return connect.NewResponse(&homelabv1.IncrementCounterResponse{Value: s.counter.Add(1)}), nil
}
func (s *server) SayHello(_ context.Context, req *connect.Request[homelabv1.SayHelloRequest]) (*connect.Response[homelabv1.SayHelloResponse], error) {
name := req.Msg.GetName()
if name == "" {
return nil, connect.NewError(connect.CodeInvalidArgument, os.ErrInvalid)
}
return connect.NewResponse(&homelabv1.SayHelloResponse{Greeting: "Hello, " + name + "!"}), nil
}
func main() {
svc := &server{lucky: rand.Int64()}
e := echo.New()
e.HideBanner = true
// ConnectRPC handler on the mux (matches /homelab.v1.HomelabService/<Method>).
mux := http.NewServeMux()
mux.Handle(homelabv1connect.NewHomelabServiceHandler(svc))
e.Any("/homelab.v1.HomelabService/*", echo.WrapHandler(mux))
// sw.js must never be cached, otherwise iOS serves a stale service worker.
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if c.Request().URL.Path == "/sw.js" || c.Request().URL.Path == "/manifest.webmanifest" {
c.Response().Header().Set("Cache-Control", "no-cache")
}
return next(c)
}
})
// Static PWA from web/dist (built by make web); HTML5 mode falls back to index.html for SPA routes.
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "web/dist",
HTML5: true,
}))
e.Logger.Fatal(e.Start(":8080"))
}
+20
View File
@@ -0,0 +1,20 @@
<!doctype html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>Homelab</title>
<meta name="theme-color" content="#1e293b" />
<!-- iOS: run standalone when added to home screen -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="Homelab" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="icon" href="/icon-512.png" />
<link rel="manifest" href="/manifest.webmanifest" />
</head>
<body>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
{
"name": "web",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"gen": "protoc --proto_path=../proto --plugin=protoc-gen-es=./node_modules/.bin/protoc-gen-es --es_out=src/gen --es_opt=target=ts ../proto/homelab/v1/homelab.proto"
},
"packageManager": "pnpm@10.6.5",
"dependencies": {
"@bufbuild/protobuf": "^2.14.0",
"@connectrpc/connect": "^2.1.2",
"@connectrpc/connect-web": "^2.1.2",
"@tailwindcss/vite": "^4.3.3",
"daisyui": "^5.7.22",
"lucide-preact": "^1.35.0",
"preact": "^10.29.8",
"tailwindcss": "^4.3.3"
},
"devDependencies": {
"@bufbuild/protoc-gen-es": "^2.14.0",
"@preact/preset-vite": "^2.10.6",
"typescript": "^7.0.2",
"vite": "^8.2.2"
}
}
+1697
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+11
View File
@@ -0,0 +1,11 @@
{
"name": "Homelab",
"short_name": "Homelab",
"start_url": "/",
"display": "standalone",
"background_color": "#0f172a",
"theme_color": "#1e293b",
"icons": [
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }
]
}
+17
View File
@@ -0,0 +1,17 @@
/* Offline shell: network-first for navigations, cache fallback when offline. */
const CACHE = "homelab-shell-v1";
self.addEventListener("install", (e) => {
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(["/", "/index.html"])));
});
self.addEventListener("activate", (e) => {
e.waitUntil(
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))),
);
});
self.addEventListener("fetch", (e) => {
if (e.request.mode !== "navigate") return;
e.respondWith(fetch(e.request).catch(() => caches.match("/index.html")));
});
+85
View File
@@ -0,0 +1,85 @@
import { useEffect, useState } from "preact/hooks";
import { createClient } from "@connectrpc/connect";
import { createConnectTransport } from "@connectrpc/connect-web";
import { Dices, Hash, Send } from "lucide-preact";
import { HomelabService } from "./gen/homelab/v1/homelab_pb";
const client = createClient(HomelabService, createConnectTransport({ baseUrl: "" }));
export function App() {
const [lucky, setLucky] = useState<number | null>(null);
const [count, setCount] = useState(0);
const [name, setName] = useState("");
const [greeting, setGreeting] = useState("");
const [error, setError] = useState("");
useEffect(() => {
client.getLuckyNumber({}).then((r) => setLucky(r.number));
}, []);
const run = async (fn: () => Promise<unknown>) => {
try {
await fn();
setError("");
} catch (e) {
setError(String(e));
}
};
return (
<div class="mx-auto max-w-md px-4 pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]">
<div class="navbar px-0">
<div class="navbar-start" />
<div class="navbar-center">
<span class="text-lg font-bold">Homelab</span>
</div>
<div class="navbar-end" />
</div>
{error && <div role="alert" class="alert alert-error text-sm">{error}</div>}
<div class="stats w-full shadow bg-base-200 mt-4">
<div class="stat">
<div class="stat-figure text-primary"><Dices size={28} /></div>
<div class="stat-title">Lucky number</div>
<div class="stat-value text-primary">{lucky ?? "…"}</div>
<div class="stat-desc">set at server start</div>
</div>
<div class="stat">
<div class="stat-figure text-secondary"><Hash size={28} /></div>
<div class="stat-title">Counter</div>
<div class="stat-value text-secondary">{count}</div>
<div class="stat-actions">
<button class="btn btn-sm btn-secondary" onClick={() => run(async () => setCount((await client.incrementCounter({})).value))}>
+1
</button>
</div>
</div>
</div>
<form
class="card bg-base-200 shadow mt-4"
onSubmit={(e) => {
e.preventDefault();
run(async () => setGreeting((await client.sayHello({ name })).greeting));
}}
>
<div class="card-body">
<h2 class="card-title text-base">Hello</h2>
<div class="flex gap-2">
<input
class="input input-bordered flex-1"
value={name}
onInput={(e) => setName((e.target as HTMLInputElement).value)}
placeholder="NAME"
/>
<button type="submit" class="btn btn-primary">
<Send size={16} /> Send
</button>
</div>
{greeting && <p class="text-xl font-semibold">{greeting}</p>}
</div>
</form>
</div>
);
}
+4
View File
@@ -0,0 +1,4 @@
@import "tailwindcss";
@plugin "daisyui" {
themes: dark --default;
}
+139
View File
@@ -0,0 +1,139 @@
// @generated by protoc-gen-es v2.14.0 with parameter "target=ts"
// @generated from file homelab/v1/homelab.proto (package homelab.v1, syntax proto3)
/* eslint-disable */
import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
import type { Message } from "@bufbuild/protobuf";
/**
* Describes the file homelab/v1/homelab.proto.
*/
export const file_homelab_v1_homelab: GenFile = /*@__PURE__*/
fileDesc("Chhob21lbGFiL3YxL2hvbWVsYWIucHJvdG8SCmhvbWVsYWIudjEiFwoVR2V0THVja3lOdW1iZXJSZXF1ZXN0IigKFkdldEx1Y2t5TnVtYmVyUmVzcG9uc2USDgoGbnVtYmVyGAEgASgDIhkKF0luY3JlbWVudENvdW50ZXJSZXF1ZXN0IikKGEluY3JlbWVudENvdW50ZXJSZXNwb25zZRINCgV2YWx1ZRgBIAEoAyIfCg9TYXlIZWxsb1JlcXVlc3QSDAoEbmFtZRgBIAEoCSIkChBTYXlIZWxsb1Jlc3BvbnNlEhAKCGdyZWV0aW5nGAEgASgJMo8CCg5Ib21lbGFiU2VydmljZRJXCg5HZXRMdWNreU51bWJlchIhLmhvbWVsYWIudjEuR2V0THVja3lOdW1iZXJSZXF1ZXN0GiIuaG9tZWxhYi52MS5HZXRMdWNreU51bWJlclJlc3BvbnNlEl0KEEluY3JlbWVudENvdW50ZXISIy5ob21lbGFiLnYxLkluY3JlbWVudENvdW50ZXJSZXF1ZXN0GiQuaG9tZWxhYi52MS5JbmNyZW1lbnRDb3VudGVyUmVzcG9uc2USRQoIU2F5SGVsbG8SGy5ob21lbGFiLnYxLlNheUhlbGxvUmVxdWVzdBocLmhvbWVsYWIudjEuU2F5SGVsbG9SZXNwb25zZUIqWihwd2EtaG9tZWxhYi1tb24vZ2VuL2hvbWVsYWIvdjE7aG9tZWxhYnYxYgZwcm90bzM");
/**
* @generated from message homelab.v1.GetLuckyNumberRequest
*/
export type GetLuckyNumberRequest = Message<"homelab.v1.GetLuckyNumberRequest"> & {
};
/**
* Describes the message homelab.v1.GetLuckyNumberRequest.
* Use `create(GetLuckyNumberRequestSchema)` to create a new message.
*/
export const GetLuckyNumberRequestSchema: GenMessage<GetLuckyNumberRequest> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 0);
/**
* @generated from message homelab.v1.GetLuckyNumberResponse
*/
export type GetLuckyNumberResponse = Message<"homelab.v1.GetLuckyNumberResponse"> & {
/**
* @generated from field: int64 number = 1;
*/
number: bigint;
};
/**
* Describes the message homelab.v1.GetLuckyNumberResponse.
* Use `create(GetLuckyNumberResponseSchema)` to create a new message.
*/
export const GetLuckyNumberResponseSchema: GenMessage<GetLuckyNumberResponse> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 1);
/**
* @generated from message homelab.v1.IncrementCounterRequest
*/
export type IncrementCounterRequest = Message<"homelab.v1.IncrementCounterRequest"> & {
};
/**
* Describes the message homelab.v1.IncrementCounterRequest.
* Use `create(IncrementCounterRequestSchema)` to create a new message.
*/
export const IncrementCounterRequestSchema: GenMessage<IncrementCounterRequest> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 2);
/**
* @generated from message homelab.v1.IncrementCounterResponse
*/
export type IncrementCounterResponse = Message<"homelab.v1.IncrementCounterResponse"> & {
/**
* @generated from field: int64 value = 1;
*/
value: bigint;
};
/**
* Describes the message homelab.v1.IncrementCounterResponse.
* Use `create(IncrementCounterResponseSchema)` to create a new message.
*/
export const IncrementCounterResponseSchema: GenMessage<IncrementCounterResponse> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 3);
/**
* @generated from message homelab.v1.SayHelloRequest
*/
export type SayHelloRequest = Message<"homelab.v1.SayHelloRequest"> & {
/**
* @generated from field: string name = 1;
*/
name: string;
};
/**
* Describes the message homelab.v1.SayHelloRequest.
* Use `create(SayHelloRequestSchema)` to create a new message.
*/
export const SayHelloRequestSchema: GenMessage<SayHelloRequest> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 4);
/**
* @generated from message homelab.v1.SayHelloResponse
*/
export type SayHelloResponse = Message<"homelab.v1.SayHelloResponse"> & {
/**
* @generated from field: string greeting = 1;
*/
greeting: string;
};
/**
* Describes the message homelab.v1.SayHelloResponse.
* Use `create(SayHelloResponseSchema)` to create a new message.
*/
export const SayHelloResponseSchema: GenMessage<SayHelloResponse> = /*@__PURE__*/
messageDesc(file_homelab_v1_homelab, 5);
/**
* @generated from service homelab.v1.HomelabService
*/
export const HomelabService: GenService<{
/**
* @generated from rpc homelab.v1.HomelabService.GetLuckyNumber
*/
getLuckyNumber: {
methodKind: "unary";
input: typeof GetLuckyNumberRequestSchema;
output: typeof GetLuckyNumberResponseSchema;
},
/**
* @generated from rpc homelab.v1.HomelabService.IncrementCounter
*/
incrementCounter: {
methodKind: "unary";
input: typeof IncrementCounterRequestSchema;
output: typeof IncrementCounterResponseSchema;
},
/**
* @generated from rpc homelab.v1.HomelabService.SayHello
*/
sayHello: {
methodKind: "unary";
input: typeof SayHelloRequestSchema;
output: typeof SayHelloResponseSchema;
},
}> = /*@__PURE__*/
serviceDesc(file_homelab_v1_homelab, 0);
+9
View File
@@ -0,0 +1,9 @@
import { render } from "preact";
import { App } from "./App";
import "./app.css";
render(<App />, document.body);
if ("serviceWorker" in navigator && import.meta.env.PROD) {
navigator.serviceWorker.register("/sw.js");
}
+15
View File
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"jsx": "react-jsx",
"jsxImportSource": "preact",
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"types": ["vite/client"]
},
"include": ["src"]
}
+13
View File
@@ -0,0 +1,13 @@
import { defineConfig } from "vite";
import preact from "@preact/preset-vite";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [preact(), tailwindcss()],
server: {
proxy: {
// Connect RPC calls in dev go straight to the Go server.
"/homelab.v1.HomelabService": "http://localhost:8080",
},
},
});