Files
dev-service/pkg/cmds/rpc.go
itzaname 8a448ea9dc
All checks were successful
continuous-integration/drone/push Build is passing
Display rate limit
2025-06-22 22:55:17 -04:00

56 lines
1.1 KiB
Go

package cmds
import (
"fmt"
"git.itzana.me/StrafesNET/dev-service/pkg/cache"
"git.itzana.me/StrafesNET/dev-service/pkg/datastore/gormstore"
"git.itzana.me/StrafesNET/dev-service/pkg/ratelimit"
"git.itzana.me/StrafesNET/dev-service/pkg/rpc"
"git.itzana.me/strafesnet/go-grpc/dev"
"github.com/redis/go-redis/v9"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"net"
)
func NewRpcCommand() *cli.Command {
return &cli.Command{
Name: "rpc",
Usage: "Run dev rpc service",
Action: rpcServer,
Flags: []cli.Flag{},
}
}
func rpcServer(ctx *cli.Context) error {
// Setup database
store, err := gormstore.New(ctx)
if err != nil {
return err
}
// Redis setup
rdb := redis.NewClient(&redis.Options{
Addr: ctx.String("redis-addr"),
Password: ctx.String("redis-pass"),
DB: ctx.Int("redis-db"),
})
// grpc server
ls, err := net.Listen("tcp", fmt.Sprintf(":%d", ctx.Int("port")))
if err != nil {
return err
}
grpcServer := grpc.NewServer()
dev.RegisterDevServiceServer(grpcServer, &rpc.Dev{
Store: store,
Limiter: ratelimit.New(rdb),
Cache: cache.NewCache(rdb, "app"),
})
return grpcServer.Serve(ls)
}