init panel-service

This commit is contained in:
2023-09-27 16:13:48 +01:00
parent 55a533c461
commit e0bd8ef953
24 changed files with 2602 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
package internal
import (
"os"
"fmt"
"strings"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func NewConfig() Config {
// Parse the log level
logLvl, err := zerolog.ParseLevel(optFromEnvFallback("LOG_LEVEL", "info"))
if err != nil {
log.Fatal().Err(err).Msg("invalid log level specified")
}
// Parse the kafka brokers
kafkaBrokers := strings.Split(optFromEnvRequire("KAFKA_BROKERS"), ",")
if len(kafkaBrokers) == 0 {
log.Fatal().Err(err).Msg("no kafka brokers provided in configuration")
}
// Create the config
cfg := Config{
RedisHost: optFromEnvRequire("REDIS_HOST"),
RedisPass: optFromEnvRequire("REDIS_PASS"),
KafkaBrokers: kafkaBrokers,
LogLevel: logLvl,
}
// Assemble the Config.PostgresURL
cfg.SetPostgresURL(
optFromEnvRequire("POSTGRES_USER"),
optFromEnvRequire("POSTGRES_PASS"),
optFromEnvRequire("POSTGRES_HOST"),
optFromEnvRequire("POSTGRES_DATABASE"),
)
return cfg
}
func optFromEnv(opt string) *string {
optValue, exists := os.LookupEnv(opt)
if !exists || optValue == "" {
return nil
}
return &optValue
}
func optFromEnvRequire(opt string) string {
optValue := optFromEnv(opt)
if optValue == nil {
log.Fatal().Str("option", opt).Msg("failed to load required config option")
}
return *optValue
}
func optFromEnvFallback(opt string, fallback string) string {
optValue := optFromEnv(opt)
if optValue == nil {
return fallback
}
return *optValue
}
type Config struct {
PostgresURL string
RedisHost string
RedisPass string
KafkaBrokers []string
LogLevel zerolog.Level
}
func (cfg *Config) SetPostgresURL(user string, pass string, host string, db string) {
cfg.PostgresURL = fmt.Sprintf("postgresql://%s:%s@%s/%s?sslmode=disable", user, pass, host, db)
}
func (cfg Config) GetPostgresURL() string {
return cfg.PostgresURL
}
func (cfg Config) GetLogLevel() zerolog.Level {
return cfg.LogLevel
}

View File

@@ -0,0 +1,80 @@
package internal
import (
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func NewServiceError(code ErrorCode, msg string) error {
return &ServiceError{
code: code,
msg: msg,
}
}
func NewServiceErrorf(code ErrorCode, msg string, args ...interface{}) error {
return NewServiceError(code, fmt.Sprintf(msg, args...))
}
func WrapServiceError(original_err error, code ErrorCode, msg string) error {
return &ServiceError{
code: code,
msg: msg,
original_err: original_err,
}
}
type ErrorCode int32
const (
UnknownErrorCode ErrorCode = iota
NotFoundErrorCode
ConflictErrorCode
ForbiddenErrorCode
InvalidArgumentErrorCode
ConnectionErrorCode
)
func (c ErrorCode) GRPCCode() codes.Code {
codeMap := map[ErrorCode]codes.Code{
UnknownErrorCode: codes.Unknown,
NotFoundErrorCode: codes.NotFound,
ConflictErrorCode: codes.AlreadyExists,
ForbiddenErrorCode: codes.PermissionDenied,
InvalidArgumentErrorCode: codes.InvalidArgument,
ConnectionErrorCode: codes.Unavailable,
}
grpcCode, mapped := codeMap[c]
if mapped {
return grpcCode
}
return codes.Unknown
}
type ServiceError struct {
code ErrorCode
msg string
original_err error
}
func (e ServiceError) Error() string {
if e.original_err != nil {
return fmt.Sprintf("%s: %s", e.msg, e.original_err.Error())
}
return e.msg
}
func (e ServiceError) Code() ErrorCode {
return e.code
}
func (e ServiceError) GRPCStatus() *status.Status {
return status.New(e.Code().GRPCCode(), e.msg)
}
func (e ServiceError) Unwrap() error {
return e.original_err
}

View File

@@ -0,0 +1,62 @@
package kafka
import (
"context"
"github.com/rs/zerolog/log"
"github.com/segmentio/kafka-go"
"google.golang.org/protobuf/proto"
"github.com/hexolan/panels/panel-service/internal"
"github.com/hexolan/panels/panel-service/internal/rpc/panelv1"
)
type PanelEventProducer struct {
writer *kafka.Writer
}
func NewPanelEventProducer(cfg internal.Config) PanelEventProducer {
writer := &kafka.Writer{
Addr: kafka.TCP(cfg.KafkaBrokers...),
Topic: "panel",
Balancer: &kafka.LeastBytes{},
}
return PanelEventProducer{writer: writer}
}
func (ep PanelEventProducer) SendEvent(event *panelv1.PanelEvent) {
// Encode the protobuf event
evtBytes, err := proto.Marshal(event)
if err != nil {
log.Panic().Err(err).Msg("failed to marshal event")
}
// Write to kafka
err = ep.writer.WriteMessages(context.Background(), kafka.Message{Value: evtBytes})
if err != nil {
// todo: implement recovery method e.g. storing failed event dispatches on DB to send on recovery (such as from Kafka going offline)
log.Panic().Err(err).Msg("failed to dispatch event")
}
}
func (ep PanelEventProducer) DispatchCreatedEvent(panel internal.Panel) {
go ep.SendEvent(&panelv1.PanelEvent{
Type: "created",
Data: panelv1.PanelToProto(&panel),
})
}
func (ep PanelEventProducer) DispatchUpdatedEvent(panel internal.Panel) {
go ep.SendEvent(&panelv1.PanelEvent{
Type: "updated",
Data: panelv1.PanelToProto(&panel),
})
}
func (ep PanelEventProducer) DispatchDeletedEvent(id int64) {
go ep.SendEvent(&panelv1.PanelEvent{
Type: "deleted",
Data: &panelv1.Panel{Id: internal.StringifyPanelId(id)},
})
}

View File

@@ -0,0 +1,78 @@
package internal
import (
"context"
"regexp"
"strconv"
"github.com/go-ozzo/ozzo-validation/v4"
"github.com/jackc/pgx/v5/pgtype"
)
// Panel Model
type Panel struct {
Id int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt pgtype.Timestamp `json:"created_at"`
UpdatedAt pgtype.Timestamp `json:"updated_at"`
}
func StringifyPanelId(id int64) string {
return strconv.FormatInt(id, 10)
}
func DestringifyPanelId(reprId string) (int64, error) {
id, err := strconv.ParseInt(reprId, 10, 64)
if err != nil || id < 1 {
return 0, NewServiceError(InvalidArgumentErrorCode, "invalid panel id")
}
return id, nil
}
// Model for creating panels
type PanelCreate struct {
Name string `json:"name"`
Description string `json:"description"`
}
func (p *PanelCreate) Validate() error {
return validation.ValidateStruct(
p,
validation.Field(&p.Name, validation.Required, validation.Length(3, 32), validation.Match(regexp.MustCompile("^[^_]\\w+[^_]$"))),
validation.Field(&p.Description, validation.Required, validation.Length(3, 512)),
)
}
// Model for updating a panel
type PanelUpdate struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
}
func (p *PanelUpdate) Validate() error {
return validation.ValidateStruct(
p,
validation.Field(&p.Name, validation.NilOrNotEmpty, validation.Length(3, 32), validation.Match(regexp.MustCompile("^[^_]\\w+[^_]$"))),
validation.Field(&p.Description, validation.NilOrNotEmpty, validation.Length(3, 512)),
)
}
// Interface methods
type PanelService interface {
PanelRepository
GetPanelByName(ctx context.Context, name string) (*Panel, error)
UpdatePanelByName(ctx context.Context, name string, data PanelUpdate) (*Panel, error)
DeletePanelByName(ctx context.Context, name string) error
}
type PanelRepository interface {
CreatePanel(ctx context.Context, data PanelCreate) (*Panel, error)
GetPanel(ctx context.Context, id int64) (*Panel, error)
GetPanelIdFromName(ctx context.Context, name string) (*int64, error)
UpdatePanel(ctx context.Context, id int64, data PanelUpdate) (*Panel, error)
DeletePanel(ctx context.Context, id int64) error
}

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS panels CASCADE;

View File

@@ -0,0 +1,10 @@
CREATE TABLE panels (
"id" serial PRIMARY KEY,
"name" varchar(32) NOT NULL,
"description" varchar(512) NOT NULL,
"created_at" timestamp NOT NULL DEFAULT timezone('utc', now()),
"updated_at" timestamp
);
CREATE UNIQUE INDEX panels_name_unique ON "panels" (LOWER("name"));
INSERT INTO panels ("name", "description") VALUES ('Panel', 'The de facto panel.') ON CONFLICT DO NOTHING;

View File

@@ -0,0 +1,140 @@
package postgres
import (
"context"
"errors"
"strings"
"encoding/json"
"github.com/rs/zerolog/log"
"github.com/doug-martin/goqu/v9"
_ "github.com/doug-martin/goqu/v9/dialect/postgres"
"github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/hexolan/panels/panel-service/internal"
)
type panelDatabaseRepo struct {
db *pgxpool.Pool
}
func NewPanelRepository(db *pgxpool.Pool) internal.PanelRepository {
return panelDatabaseRepo{
db: db,
}
}
func (r panelDatabaseRepo) transformToPatchData(data internal.PanelUpdate) goqu.Record {
// Ensure updated_at field is changed
patchData := goqu.Record{"updated_at": goqu.L("timezone('utc', now())")}
// Marshal the data to remove omitted keys
marshalled, _ := json.Marshal(data)
_ = json.Unmarshal(marshalled, &patchData)
return patchData
}
func (r panelDatabaseRepo) GetPanelIdFromName(ctx context.Context, name string) (*int64, error) {
var id int64
err := r.db.QueryRow(ctx, "SELECT id FROM panels WHERE LOWER(name)=LOWER($1)", name).Scan(&id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, internal.WrapServiceError(err, internal.NotFoundErrorCode, "panel not found")
} else if strings.Contains(err.Error(), "failed to connect to") {
return nil, internal.WrapServiceError(err, internal.ConnectionErrorCode, "failed to connect to database")
}
log.Error().Err(err).Msg("unaccounted error whilst getting panel ID from name")
return nil, internal.WrapServiceError(err, internal.UnknownErrorCode, "failed to get panel")
}
return &id, nil
}
func (r panelDatabaseRepo) CreatePanel(ctx context.Context, data internal.PanelCreate) (*internal.Panel, error) {
var id int64
err := r.db.QueryRow(ctx, "INSERT INTO panels (name, description) VALUES ($1, $2) RETURNING id", data.Name, data.Description).Scan(&id)
if err != nil {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
if pgerrcode.IsIntegrityConstraintViolation(pgErr.Code) {
return nil, internal.WrapServiceError(err, internal.ConflictErrorCode, "panel name not unique")
}
} else if strings.Contains(err.Error(), "failed to connect to") {
return nil, internal.WrapServiceError(err, internal.ConnectionErrorCode, "failed to connect to database")
}
log.Error().Err(err).Msg("unaccounted error whilst creating panel")
return nil, internal.WrapServiceError(err, internal.UnknownErrorCode, "failed to create panel")
}
return r.GetPanel(ctx, id)
}
func (r panelDatabaseRepo) GetPanel(ctx context.Context, id int64) (*internal.Panel, error) {
var panel internal.Panel
row := r.db.QueryRow(ctx, "SELECT id, name, description, created_at, updated_at FROM panels WHERE id=$1", id)
err := row.Scan(&panel.Id, &panel.Name, &panel.Description, &panel.CreatedAt, &panel.UpdatedAt)
if err != nil {
if err == pgx.ErrNoRows {
return nil, internal.WrapServiceError(err, internal.NotFoundErrorCode, "panel not found")
} else if strings.Contains(err.Error(), "failed to connect to") {
return nil, internal.WrapServiceError(err, internal.ConnectionErrorCode, "failed to connect to database")
}
log.Error().Err(err).Msg("unaccounted error whilst getting panel")
return nil, internal.WrapServiceError(err, internal.UnknownErrorCode, "failed to get panel")
}
return &panel, nil
}
func (r panelDatabaseRepo) UpdatePanel(ctx context.Context, id int64, data internal.PanelUpdate) (*internal.Panel, error) {
patchData := r.transformToPatchData(data)
// Build a statement to update the panel
statement, args, _ := goqu.Dialect("postgres").Update("panels").Prepared(true).Set(patchData).Where(goqu.C("id").Eq(id)).ToSQL()
// Execute the query
result, err := r.db.Exec(ctx, statement, args...)
if err != nil {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
if pgerrcode.IsIntegrityConstraintViolation(pgErr.Code) {
return nil, internal.WrapServiceError(err, internal.ConflictErrorCode, "panel name not unique")
}
} else if strings.Contains(err.Error(), "failed to connect to") {
return nil, internal.WrapServiceError(err, internal.ConnectionErrorCode, "failed to connect to database")
}
log.Error().Err(err).Msg("unaccounted error whilst updating panel")
return nil, internal.WrapServiceError(err, internal.UnknownErrorCode, "failed to update panel")
}
// Check if any rows were affected from the query
rows_affected := result.RowsAffected()
if rows_affected != 1 {
return nil, internal.NewServiceError(internal.NotFoundErrorCode, "panel not found")
}
return r.GetPanel(ctx, id)
}
func (r panelDatabaseRepo) DeletePanel(ctx context.Context, id int64) error {
// Attempt to delete the panel
result, err := r.db.Exec(ctx, "DELETE FROM panels WHERE id=$1", id)
if err != nil {
if strings.Contains(err.Error(), "failed to connect to") {
return internal.WrapServiceError(err, internal.ConnectionErrorCode, "failed to connect to database")
}
log.Error().Err(err).Msg("unaccounted error whilst deleting panel")
return internal.WrapServiceError(err, internal.UnknownErrorCode, "failed to delete panel")
}
// Check if any rows were affected
rows_affected := result.RowsAffected()
if rows_affected != 1 {
return internal.NewServiceError(internal.NotFoundErrorCode, "panel not found")
}
return nil
}

View File

@@ -0,0 +1,24 @@
package postgres
import (
"context"
"github.com/rs/zerolog/log"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/hexolan/panels/panel-service/internal"
)
func NewPostgresInterface(ctx context.Context, cfg internal.Config) *pgxpool.Pool {
db, err := pgxpool.New(ctx, cfg.GetPostgresURL())
if err != nil {
log.Panic().Err(err).Caller().Msg("")
}
err = db.Ping(ctx)
if err != nil {
log.Warn().Err(err).Msg("failed Postgres ping")
}
return db
}

View File

@@ -0,0 +1,123 @@
package redis
import (
"time"
"context"
"encoding/json"
"github.com/rs/zerolog/log"
"github.com/redis/go-redis/v9"
"github.com/hexolan/panels/panel-service/internal"
)
type panelCacheRepo struct {
rdb *redis.Client
repo internal.PanelRepository
}
func NewPanelRepository(rdb *redis.Client, repo internal.PanelRepository) internal.PanelRepository {
return panelCacheRepo{
rdb: rdb,
repo: repo,
}
}
func (r panelCacheRepo) getCachedPanel(ctx context.Context, id int64) *internal.Panel {
value, err := r.rdb.Get(ctx, internal.StringifyPanelId(id)).Result()
if err == redis.Nil {
return nil
} else if err != nil {
log.Error().Err(err).Msg("failed to get cached panel")
return nil
}
var panel internal.Panel
err = json.Unmarshal([]byte(value), &panel)
if err != nil {
log.Error().Err(err).Msg("failed to unmarshal cached panel")
return nil
}
return &panel
}
func (r panelCacheRepo) purgeCachedPanel(ctx context.Context, id int64) {
err := r.rdb.Del(ctx, internal.StringifyPanelId(id)).Err()
if err != nil && err != redis.Nil {
log.Error().Err(err).Msg("error while purging cached panel")
}
}
func (r panelCacheRepo) cachePanel(ctx context.Context, panel *internal.Panel) {
value, err := json.Marshal(panel)
if err != nil {
log.Error().Err(err).Msg("failed to marshal panel for caching")
return
}
err = r.rdb.Set(ctx, internal.StringifyPanelId(panel.Id), string(value), 5 * time.Minute).Err()
if err != nil {
log.Error().Err(err).Msg("failed to cache panel")
return
}
}
func (r panelCacheRepo) GetPanelIdFromName(ctx context.Context, name string) (*int64, error) {
// This is not cached for safety with UpdatePanel and DeletePanel methods.
return r.repo.GetPanelIdFromName(ctx, name)
}
func (r panelCacheRepo) CreatePanel(ctx context.Context, data internal.PanelCreate) (*internal.Panel, error) {
// Create the panel with the downstream DB repo.
panel, err := r.repo.CreatePanel(ctx, data)
if err != nil {
return panel, err
}
// Cache and return the created panel.
r.cachePanel(ctx, panel)
return panel, err
}
func (r panelCacheRepo) GetPanel(ctx context.Context, id int64) (*internal.Panel, error) {
// Check for a cached version of the panel.
if panel := r.getCachedPanel(ctx, id); panel != nil {
return panel, nil
}
// Panel is not cached. Fetch from the DB repo.
panel, err := r.repo.GetPanel(ctx, id)
if err != nil {
return panel, err
}
// Cache and return the fetched panel.
r.cachePanel(ctx, panel)
return panel, err
}
func (r panelCacheRepo) UpdatePanel(ctx context.Context, id int64, data internal.PanelUpdate) (*internal.Panel, error) {
// Update the panel at the downstream repo.
panel, err := r.repo.UpdatePanel(ctx, id, data)
if err != nil {
return panel, err
}
// Cache and return the updated panel.
r.cachePanel(ctx, panel)
return panel, err
}
func (r panelCacheRepo) DeletePanel(ctx context.Context, id int64) error {
// Delete the panel downstream.
err := r.repo.DeletePanel(ctx, id)
if err != nil {
return err
}
// Purge any cached version of the panel.
r.purgeCachedPanel(ctx, id)
return err
}

View File

@@ -0,0 +1,29 @@
package redis
import (
"time"
"context"
"github.com/rs/zerolog/log"
"github.com/redis/go-redis/v9"
"github.com/hexolan/panels/panel-service/internal"
)
func NewRedisInterface(ctx context.Context, cfg internal.Config) *redis.Client {
rdb := redis.NewClient(&redis.Options{
Addr: cfg.RedisHost,
Password: cfg.RedisPass,
DB: 0,
DialTimeout: time.Millisecond * 250,
ReadTimeout: time.Millisecond * 500,
})
_, err := rdb.Ping(ctx).Result()
if err != nil {
log.Warn().Err(err).Msg("failed Redis ping")
}
return rdb
}

View File

@@ -0,0 +1,162 @@
package rpc
import (
"context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
"github.com/hexolan/panels/panel-service/internal"
pb "github.com/hexolan/panels/panel-service/internal/rpc/panelv1"
)
type panelServer struct {
pb.UnimplementedPanelServiceServer
service internal.PanelService
}
func NewPanelServer(service internal.PanelService) panelServer {
return panelServer{service: service}
}
func (svr *panelServer) CreatePanel(ctx context.Context, request *pb.CreatePanelRequest) (*pb.Panel, error) {
// Ensure the required args are provided
if request.GetData() == nil {
return nil, status.Error(codes.InvalidArgument, "malformed request")
}
// Convert to business model
data := pb.PanelCreateFromProto(request.GetData())
// Attempt to create the panel
panel, err := svr.service.CreatePanel(ctx, data)
if err != nil {
return nil, err
}
return pb.PanelToProto(panel), nil
}
func (svr *panelServer) GetPanel(ctx context.Context, request *pb.GetPanelByIdRequest) (*pb.Panel, error) {
// Ensure the required args are provided
if request.GetId() == "" {
return nil, status.Error(codes.InvalidArgument, "panel id not provided")
}
// Convert to business model
id, err := internal.DestringifyPanelId(request.GetId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid panel id")
}
// Attempt to get the panel
panel, err := svr.service.GetPanel(ctx, id)
if err != nil {
return nil, err
}
return pb.PanelToProto(panel), nil
}
func (svr *panelServer) GetPanelByName(ctx context.Context, request *pb.GetPanelByNameRequest) (*pb.Panel, error) {
// Ensure the required args are provided
var name string = request.GetName()
if request.GetName() == "" {
return nil, status.Error(codes.InvalidArgument, "invalid panel name")
}
// Attempt to delete the panel
panel, err := svr.service.GetPanelByName(ctx, name)
if err != nil {
return nil, err
}
return pb.PanelToProto(panel), nil
}
func (svr *panelServer) UpdatePanel(ctx context.Context, request *pb.UpdatePanelByIdRequest) (*pb.Panel, error) {
// Ensure the required args are provided
if request.GetId() == "" {
return nil, status.Error(codes.InvalidArgument, "panel id not provided")
}
// Convert to ID to business model
id, err := internal.DestringifyPanelId(request.GetId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid panel id")
}
// Ensure that the data values have been provided
if request.GetData() == nil {
return nil, status.Error(codes.InvalidArgument, "malformed request")
}
// Convert data to business model
data := pb.PanelUpdateFromProto(request.GetData())
// Attempt to update the panel
panel, err := svr.service.UpdatePanel(ctx, id, data)
if err != nil {
return nil, err
}
return pb.PanelToProto(panel), nil
}
func (svr *panelServer) UpdatePanelByName(ctx context.Context, request *pb.UpdatePanelByNameRequest) (*pb.Panel, error) {
// Ensure the required args are provided
var name string = request.GetName()
if name == "" {
return nil, status.Error(codes.InvalidArgument, "invalid panel name")
}
if request.GetData() == nil {
return nil, status.Error(codes.InvalidArgument, "malformed request")
}
// Convert data to business model
data := pb.PanelUpdateFromProto(request.GetData())
// Attempt to update the panel
panel, err := svr.service.UpdatePanelByName(ctx, name, data)
if err != nil {
return nil, err
}
return pb.PanelToProto(panel), nil
}
func (svr *panelServer) DeletePanel(ctx context.Context, request *pb.DeletePanelByIdRequest) (*emptypb.Empty, error) {
// Ensure the required args are provided
if request.GetId() == "" {
return nil, status.Error(codes.InvalidArgument, "panel id not provided")
}
// Convert id to business model
id, err := internal.DestringifyPanelId(request.GetId())
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid panel id")
}
// Attempt to delete the panel
err = svr.service.DeletePanel(ctx, id)
if err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}
func (svr *panelServer) DeletePanelByName(ctx context.Context, request *pb.DeletePanelByNameRequest) (*emptypb.Empty, error) {
// Ensure the required args are provided
var name string = request.GetName()
if name == "" {
return nil, status.Error(codes.InvalidArgument, "invalid panel name")
}
// Attempt to delete the panel
err := svr.service.DeletePanelByName(ctx, name)
if err != nil {
return nil, err
}
return &emptypb.Empty{}, nil
}

View File

@@ -0,0 +1,58 @@
package panelv1
import (
"encoding/json"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
"github.com/hexolan/panels/panel-service/internal"
)
// Panel -> Protobuf 'Panel'
func PanelToProto(panel *internal.Panel) *Panel {
proto := Panel{
Id: internal.StringifyPanelId(panel.Id),
Name: panel.Name,
Description: panel.Description,
CreatedAt: timestamppb.New(panel.CreatedAt.Time),
}
// convert nullable attributes to PB form (if present)
if panel.UpdatedAt.Valid == true {
proto.UpdatedAt = timestamppb.New(panel.UpdatedAt.Time)
}
return &proto
}
// Protobuf 'Panel' -> Panel
func PanelFromProto(proto *Panel) (*internal.Panel, error) {
marshalled, err := json.Marshal(proto)
if err != nil {
return nil, err
}
var panel internal.Panel
err = json.Unmarshal(marshalled, &panel)
if err != nil {
return nil, err
}
return &panel, nil
}
// Protobuf 'PanelMutable' -> PanelCreate
func PanelCreateFromProto(proto *PanelMutable) internal.PanelCreate {
return internal.PanelCreate{
Name: proto.GetName(),
Description: proto.GetDescription(),
}
}
// Protobuf 'PanelMutable' -> PanelUpdate
func PanelUpdateFromProto(proto *PanelMutable) internal.PanelUpdate {
return internal.PanelUpdate{
Name: proto.Name,
Description: proto.Description,
}
}

View File

@@ -0,0 +1,861 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.28.1
// protoc v4.23.4
// source: panel.proto
package panelv1
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
reflect "reflect"
sync "sync"
)
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 Panel struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
CreatedAt *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=created_at,json=createdAt,proto3" json:"created_at,omitempty"`
UpdatedAt *timestamppb.Timestamp `protobuf:"bytes,5,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
}
func (x *Panel) Reset() {
*x = Panel{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *Panel) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*Panel) ProtoMessage() {}
func (x *Panel) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use Panel.ProtoReflect.Descriptor instead.
func (*Panel) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{0}
}
func (x *Panel) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *Panel) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *Panel) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *Panel) GetCreatedAt() *timestamppb.Timestamp {
if x != nil {
return x.CreatedAt
}
return nil
}
func (x *Panel) GetUpdatedAt() *timestamppb.Timestamp {
if x != nil {
return x.UpdatedAt
}
return nil
}
type PanelMutable struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name *string `protobuf:"bytes,1,opt,name=name,proto3,oneof" json:"name,omitempty"`
Description *string `protobuf:"bytes,2,opt,name=description,proto3,oneof" json:"description,omitempty"`
}
func (x *PanelMutable) Reset() {
*x = PanelMutable{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PanelMutable) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PanelMutable) ProtoMessage() {}
func (x *PanelMutable) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PanelMutable.ProtoReflect.Descriptor instead.
func (*PanelMutable) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{1}
}
func (x *PanelMutable) GetName() string {
if x != nil && x.Name != nil {
return *x.Name
}
return ""
}
func (x *PanelMutable) GetDescription() string {
if x != nil && x.Description != nil {
return *x.Description
}
return ""
}
type CreatePanelRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Data *PanelMutable `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *CreatePanelRequest) Reset() {
*x = CreatePanelRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CreatePanelRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CreatePanelRequest) ProtoMessage() {}
func (x *CreatePanelRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CreatePanelRequest.ProtoReflect.Descriptor instead.
func (*CreatePanelRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{2}
}
func (x *CreatePanelRequest) GetData() *PanelMutable {
if x != nil {
return x.Data
}
return nil
}
type GetPanelByIdRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *GetPanelByIdRequest) Reset() {
*x = GetPanelByIdRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetPanelByIdRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetPanelByIdRequest) ProtoMessage() {}
func (x *GetPanelByIdRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetPanelByIdRequest.ProtoReflect.Descriptor instead.
func (*GetPanelByIdRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{3}
}
func (x *GetPanelByIdRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type GetPanelByNameRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *GetPanelByNameRequest) Reset() {
*x = GetPanelByNameRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *GetPanelByNameRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetPanelByNameRequest) ProtoMessage() {}
func (x *GetPanelByNameRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetPanelByNameRequest.ProtoReflect.Descriptor instead.
func (*GetPanelByNameRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{4}
}
func (x *GetPanelByNameRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
type UpdatePanelByIdRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Data *PanelMutable `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *UpdatePanelByIdRequest) Reset() {
*x = UpdatePanelByIdRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpdatePanelByIdRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdatePanelByIdRequest) ProtoMessage() {}
func (x *UpdatePanelByIdRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdatePanelByIdRequest.ProtoReflect.Descriptor instead.
func (*UpdatePanelByIdRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{5}
}
func (x *UpdatePanelByIdRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
func (x *UpdatePanelByIdRequest) GetData() *PanelMutable {
if x != nil {
return x.Data
}
return nil
}
type UpdatePanelByNameRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Data *PanelMutable `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *UpdatePanelByNameRequest) Reset() {
*x = UpdatePanelByNameRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpdatePanelByNameRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdatePanelByNameRequest) ProtoMessage() {}
func (x *UpdatePanelByNameRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[6]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpdatePanelByNameRequest.ProtoReflect.Descriptor instead.
func (*UpdatePanelByNameRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{6}
}
func (x *UpdatePanelByNameRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *UpdatePanelByNameRequest) GetData() *PanelMutable {
if x != nil {
return x.Data
}
return nil
}
type DeletePanelByIdRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
}
func (x *DeletePanelByIdRequest) Reset() {
*x = DeletePanelByIdRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[7]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeletePanelByIdRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeletePanelByIdRequest) ProtoMessage() {}
func (x *DeletePanelByIdRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[7]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeletePanelByIdRequest.ProtoReflect.Descriptor instead.
func (*DeletePanelByIdRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{7}
}
func (x *DeletePanelByIdRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type DeletePanelByNameRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *DeletePanelByNameRequest) Reset() {
*x = DeletePanelByNameRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[8]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeletePanelByNameRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeletePanelByNameRequest) ProtoMessage() {}
func (x *DeletePanelByNameRequest) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[8]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeletePanelByNameRequest.ProtoReflect.Descriptor instead.
func (*DeletePanelByNameRequest) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{8}
}
func (x *DeletePanelByNameRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
// Kafka Event Schema
type PanelEvent struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"`
Data *Panel `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
}
func (x *PanelEvent) Reset() {
*x = PanelEvent{}
if protoimpl.UnsafeEnabled {
mi := &file_panel_proto_msgTypes[9]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PanelEvent) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PanelEvent) ProtoMessage() {}
func (x *PanelEvent) ProtoReflect() protoreflect.Message {
mi := &file_panel_proto_msgTypes[9]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PanelEvent.ProtoReflect.Descriptor instead.
func (*PanelEvent) Descriptor() ([]byte, []int) {
return file_panel_proto_rawDescGZIP(), []int{9}
}
func (x *PanelEvent) GetType() string {
if x != nil {
return x.Type
}
return ""
}
func (x *PanelEvent) GetData() *Panel {
if x != nil {
return x.Data
}
return nil
}
var File_panel_proto protoreflect.FileDescriptor
var file_panel_proto_rawDesc = []byte{
0x0a, 0x0b, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0f, 0x70,
0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x1a, 0x1b,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f,
0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x1f, 0x67, 0x6f, 0x6f,
0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xc3, 0x01, 0x0a,
0x05, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65,
0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x39, 0x0a, 0x0a,
0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x63, 0x72,
0x65, 0x61, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x39, 0x0a, 0x0a, 0x75, 0x70, 0x64, 0x61, 0x74,
0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f,
0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69,
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64,
0x41, 0x74, 0x22, 0x67, 0x0a, 0x0c, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x4d, 0x75, 0x74, 0x61, 0x62,
0x6c, 0x65, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x12, 0x25, 0x0a, 0x0b, 0x64,
0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09,
0x48, 0x01, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x88,
0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0e, 0x0a, 0x0c, 0x5f,
0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x47, 0x0a, 0x12, 0x43,
0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x1d, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76,
0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x4d, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x04,
0x64, 0x61, 0x74, 0x61, 0x22, 0x25, 0x0a, 0x13, 0x47, 0x65, 0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c,
0x42, 0x79, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x2b, 0x0a, 0x15, 0x47,
0x65, 0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x5b, 0x0a, 0x16, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02,
0x69, 0x64, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b,
0x32, 0x1d, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e,
0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x4d, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x52,
0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x61, 0x0a, 0x18, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50,
0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x31, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20,
0x01, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e,
0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x4d, 0x75, 0x74, 0x61, 0x62,
0x6c, 0x65, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x28, 0x0a, 0x16, 0x44, 0x65, 0x6c, 0x65,
0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02,
0x69, 0x64, 0x22, 0x2e, 0x0a, 0x18, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65,
0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12,
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
0x6d, 0x65, 0x22, 0x4c, 0x0a, 0x0a, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x45, 0x76, 0x65, 0x6e, 0x74,
0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
0x74, 0x79, 0x70, 0x65, 0x12, 0x2a, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01,
0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65,
0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61,
0x32, 0xd4, 0x04, 0x0a, 0x0c, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x4c, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c,
0x12, 0x23, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e,
0x76, 0x31, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70,
0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x22, 0x00, 0x12,
0x4a, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x12, 0x24, 0x2e, 0x70, 0x61,
0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x47, 0x65,
0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c,
0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x22, 0x00, 0x12, 0x52, 0x0a, 0x0e, 0x47,
0x65, 0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x26, 0x2e,
0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e,
0x47, 0x65, 0x74, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70,
0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x22, 0x00, 0x12,
0x50, 0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x12, 0x27,
0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31,
0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x49, 0x64,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73,
0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x22,
0x00, 0x12, 0x58, 0x0a, 0x11, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c,
0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x29, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e,
0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x50,
0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x74, 0x1a, 0x16, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c,
0x2e, 0x76, 0x31, 0x2e, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x22, 0x00, 0x12, 0x50, 0x0a, 0x0b, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x12, 0x27, 0x2e, 0x70, 0x61, 0x6e,
0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c,
0x65, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x49, 0x64, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x12, 0x58, 0x0a,
0x11, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c, 0x42, 0x79, 0x4e, 0x61,
0x6d, 0x65, 0x12, 0x29, 0x2e, 0x70, 0x61, 0x6e, 0x65, 0x6c, 0x73, 0x2e, 0x70, 0x61, 0x6e, 0x65,
0x6c, 0x2e, 0x76, 0x31, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x50, 0x61, 0x6e, 0x65, 0x6c,
0x42, 0x79, 0x4e, 0x61, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_panel_proto_rawDescOnce sync.Once
file_panel_proto_rawDescData = file_panel_proto_rawDesc
)
func file_panel_proto_rawDescGZIP() []byte {
file_panel_proto_rawDescOnce.Do(func() {
file_panel_proto_rawDescData = protoimpl.X.CompressGZIP(file_panel_proto_rawDescData)
})
return file_panel_proto_rawDescData
}
var file_panel_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_panel_proto_goTypes = []interface{}{
(*Panel)(nil), // 0: panels.panel.v1.Panel
(*PanelMutable)(nil), // 1: panels.panel.v1.PanelMutable
(*CreatePanelRequest)(nil), // 2: panels.panel.v1.CreatePanelRequest
(*GetPanelByIdRequest)(nil), // 3: panels.panel.v1.GetPanelByIdRequest
(*GetPanelByNameRequest)(nil), // 4: panels.panel.v1.GetPanelByNameRequest
(*UpdatePanelByIdRequest)(nil), // 5: panels.panel.v1.UpdatePanelByIdRequest
(*UpdatePanelByNameRequest)(nil), // 6: panels.panel.v1.UpdatePanelByNameRequest
(*DeletePanelByIdRequest)(nil), // 7: panels.panel.v1.DeletePanelByIdRequest
(*DeletePanelByNameRequest)(nil), // 8: panels.panel.v1.DeletePanelByNameRequest
(*PanelEvent)(nil), // 9: panels.panel.v1.PanelEvent
(*timestamppb.Timestamp)(nil), // 10: google.protobuf.Timestamp
(*emptypb.Empty)(nil), // 11: google.protobuf.Empty
}
var file_panel_proto_depIdxs = []int32{
10, // 0: panels.panel.v1.Panel.created_at:type_name -> google.protobuf.Timestamp
10, // 1: panels.panel.v1.Panel.updated_at:type_name -> google.protobuf.Timestamp
1, // 2: panels.panel.v1.CreatePanelRequest.data:type_name -> panels.panel.v1.PanelMutable
1, // 3: panels.panel.v1.UpdatePanelByIdRequest.data:type_name -> panels.panel.v1.PanelMutable
1, // 4: panels.panel.v1.UpdatePanelByNameRequest.data:type_name -> panels.panel.v1.PanelMutable
0, // 5: panels.panel.v1.PanelEvent.data:type_name -> panels.panel.v1.Panel
2, // 6: panels.panel.v1.PanelService.CreatePanel:input_type -> panels.panel.v1.CreatePanelRequest
3, // 7: panels.panel.v1.PanelService.GetPanel:input_type -> panels.panel.v1.GetPanelByIdRequest
4, // 8: panels.panel.v1.PanelService.GetPanelByName:input_type -> panels.panel.v1.GetPanelByNameRequest
5, // 9: panels.panel.v1.PanelService.UpdatePanel:input_type -> panels.panel.v1.UpdatePanelByIdRequest
6, // 10: panels.panel.v1.PanelService.UpdatePanelByName:input_type -> panels.panel.v1.UpdatePanelByNameRequest
7, // 11: panels.panel.v1.PanelService.DeletePanel:input_type -> panels.panel.v1.DeletePanelByIdRequest
8, // 12: panels.panel.v1.PanelService.DeletePanelByName:input_type -> panels.panel.v1.DeletePanelByNameRequest
0, // 13: panels.panel.v1.PanelService.CreatePanel:output_type -> panels.panel.v1.Panel
0, // 14: panels.panel.v1.PanelService.GetPanel:output_type -> panels.panel.v1.Panel
0, // 15: panels.panel.v1.PanelService.GetPanelByName:output_type -> panels.panel.v1.Panel
0, // 16: panels.panel.v1.PanelService.UpdatePanel:output_type -> panels.panel.v1.Panel
0, // 17: panels.panel.v1.PanelService.UpdatePanelByName:output_type -> panels.panel.v1.Panel
11, // 18: panels.panel.v1.PanelService.DeletePanel:output_type -> google.protobuf.Empty
11, // 19: panels.panel.v1.PanelService.DeletePanelByName:output_type -> google.protobuf.Empty
13, // [13:20] is the sub-list for method output_type
6, // [6:13] is the sub-list for method input_type
6, // [6:6] is the sub-list for extension type_name
6, // [6:6] is the sub-list for extension extendee
0, // [0:6] is the sub-list for field type_name
}
func init() { file_panel_proto_init() }
func file_panel_proto_init() {
if File_panel_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_panel_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*Panel); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PanelMutable); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CreatePanelRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetPanelByIdRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*GetPanelByNameRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpdatePanelByIdRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpdatePanelByNameRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeletePanelByIdRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeletePanelByNameRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_panel_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PanelEvent); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
file_panel_proto_msgTypes[1].OneofWrappers = []interface{}{}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_panel_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_panel_proto_goTypes,
DependencyIndexes: file_panel_proto_depIdxs,
MessageInfos: file_panel_proto_msgTypes,
}.Build()
File_panel_proto = out.File
file_panel_proto_rawDesc = nil
file_panel_proto_goTypes = nil
file_panel_proto_depIdxs = nil
}

View File

@@ -0,0 +1,322 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.2.0
// - protoc v4.23.4
// source: panel.proto
package panelv1
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// PanelServiceClient is the client API for PanelService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type PanelServiceClient interface {
CreatePanel(ctx context.Context, in *CreatePanelRequest, opts ...grpc.CallOption) (*Panel, error)
GetPanel(ctx context.Context, in *GetPanelByIdRequest, opts ...grpc.CallOption) (*Panel, error)
GetPanelByName(ctx context.Context, in *GetPanelByNameRequest, opts ...grpc.CallOption) (*Panel, error)
UpdatePanel(ctx context.Context, in *UpdatePanelByIdRequest, opts ...grpc.CallOption) (*Panel, error)
UpdatePanelByName(ctx context.Context, in *UpdatePanelByNameRequest, opts ...grpc.CallOption) (*Panel, error)
DeletePanel(ctx context.Context, in *DeletePanelByIdRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
DeletePanelByName(ctx context.Context, in *DeletePanelByNameRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
type panelServiceClient struct {
cc grpc.ClientConnInterface
}
func NewPanelServiceClient(cc grpc.ClientConnInterface) PanelServiceClient {
return &panelServiceClient{cc}
}
func (c *panelServiceClient) CreatePanel(ctx context.Context, in *CreatePanelRequest, opts ...grpc.CallOption) (*Panel, error) {
out := new(Panel)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/CreatePanel", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) GetPanel(ctx context.Context, in *GetPanelByIdRequest, opts ...grpc.CallOption) (*Panel, error) {
out := new(Panel)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/GetPanel", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) GetPanelByName(ctx context.Context, in *GetPanelByNameRequest, opts ...grpc.CallOption) (*Panel, error) {
out := new(Panel)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/GetPanelByName", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) UpdatePanel(ctx context.Context, in *UpdatePanelByIdRequest, opts ...grpc.CallOption) (*Panel, error) {
out := new(Panel)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/UpdatePanel", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) UpdatePanelByName(ctx context.Context, in *UpdatePanelByNameRequest, opts ...grpc.CallOption) (*Panel, error) {
out := new(Panel)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/UpdatePanelByName", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) DeletePanel(ctx context.Context, in *DeletePanelByIdRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/DeletePanel", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *panelServiceClient) DeletePanelByName(ctx context.Context, in *DeletePanelByNameRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, "/panels.panel.v1.PanelService/DeletePanelByName", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// PanelServiceServer is the server API for PanelService service.
// All implementations must embed UnimplementedPanelServiceServer
// for forward compatibility
type PanelServiceServer interface {
CreatePanel(context.Context, *CreatePanelRequest) (*Panel, error)
GetPanel(context.Context, *GetPanelByIdRequest) (*Panel, error)
GetPanelByName(context.Context, *GetPanelByNameRequest) (*Panel, error)
UpdatePanel(context.Context, *UpdatePanelByIdRequest) (*Panel, error)
UpdatePanelByName(context.Context, *UpdatePanelByNameRequest) (*Panel, error)
DeletePanel(context.Context, *DeletePanelByIdRequest) (*emptypb.Empty, error)
DeletePanelByName(context.Context, *DeletePanelByNameRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedPanelServiceServer()
}
// UnimplementedPanelServiceServer must be embedded to have forward compatible implementations.
type UnimplementedPanelServiceServer struct {
}
func (UnimplementedPanelServiceServer) CreatePanel(context.Context, *CreatePanelRequest) (*Panel, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreatePanel not implemented")
}
func (UnimplementedPanelServiceServer) GetPanel(context.Context, *GetPanelByIdRequest) (*Panel, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPanel not implemented")
}
func (UnimplementedPanelServiceServer) GetPanelByName(context.Context, *GetPanelByNameRequest) (*Panel, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPanelByName not implemented")
}
func (UnimplementedPanelServiceServer) UpdatePanel(context.Context, *UpdatePanelByIdRequest) (*Panel, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdatePanel not implemented")
}
func (UnimplementedPanelServiceServer) UpdatePanelByName(context.Context, *UpdatePanelByNameRequest) (*Panel, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdatePanelByName not implemented")
}
func (UnimplementedPanelServiceServer) DeletePanel(context.Context, *DeletePanelByIdRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeletePanel not implemented")
}
func (UnimplementedPanelServiceServer) DeletePanelByName(context.Context, *DeletePanelByNameRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeletePanelByName not implemented")
}
func (UnimplementedPanelServiceServer) mustEmbedUnimplementedPanelServiceServer() {}
// UnsafePanelServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to PanelServiceServer will
// result in compilation errors.
type UnsafePanelServiceServer interface {
mustEmbedUnimplementedPanelServiceServer()
}
func RegisterPanelServiceServer(s grpc.ServiceRegistrar, srv PanelServiceServer) {
s.RegisterService(&PanelService_ServiceDesc, srv)
}
func _PanelService_CreatePanel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CreatePanelRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).CreatePanel(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/CreatePanel",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).CreatePanel(ctx, req.(*CreatePanelRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_GetPanel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPanelByIdRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).GetPanel(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/GetPanel",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).GetPanel(ctx, req.(*GetPanelByIdRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_GetPanelByName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPanelByNameRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).GetPanelByName(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/GetPanelByName",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).GetPanelByName(ctx, req.(*GetPanelByNameRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_UpdatePanel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdatePanelByIdRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).UpdatePanel(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/UpdatePanel",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).UpdatePanel(ctx, req.(*UpdatePanelByIdRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_UpdatePanelByName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdatePanelByNameRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).UpdatePanelByName(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/UpdatePanelByName",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).UpdatePanelByName(ctx, req.(*UpdatePanelByNameRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_DeletePanel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeletePanelByIdRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).DeletePanel(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/DeletePanel",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).DeletePanel(ctx, req.(*DeletePanelByIdRequest))
}
return interceptor(ctx, in, info, handler)
}
func _PanelService_DeletePanelByName_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DeletePanelByNameRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(PanelServiceServer).DeletePanelByName(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/panels.panel.v1.PanelService/DeletePanelByName",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(PanelServiceServer).DeletePanelByName(ctx, req.(*DeletePanelByNameRequest))
}
return interceptor(ctx, in, info, handler)
}
// PanelService_ServiceDesc is the grpc.ServiceDesc for PanelService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var PanelService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "panels.panel.v1.PanelService",
HandlerType: (*PanelServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "CreatePanel",
Handler: _PanelService_CreatePanel_Handler,
},
{
MethodName: "GetPanel",
Handler: _PanelService_GetPanel_Handler,
},
{
MethodName: "GetPanelByName",
Handler: _PanelService_GetPanelByName_Handler,
},
{
MethodName: "UpdatePanel",
Handler: _PanelService_UpdatePanel_Handler,
},
{
MethodName: "UpdatePanelByName",
Handler: _PanelService_UpdatePanelByName_Handler,
},
{
MethodName: "DeletePanel",
Handler: _PanelService_DeletePanel_Handler,
},
{
MethodName: "DeletePanelByName",
Handler: _PanelService_DeletePanelByName_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "panel.proto",
}

View File

@@ -0,0 +1,77 @@
package rpc
import (
"net"
"context"
"google.golang.org/grpc"
"google.golang.org/grpc/health"
"google.golang.org/grpc/health/grpc_health_v1"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/hexolan/panels/panel-service/internal"
"github.com/hexolan/panels/panel-service/internal/rpc/panelv1"
)
type RPCServer struct {
grpcSvr *grpc.Server
}
func NewRPCServer(panelService internal.PanelService) *RPCServer {
logger := log.Logger.With().Timestamp().Str("src", "rpc").Logger()
svr := grpc.NewServer(
grpc.ChainUnaryInterceptor(
logging.UnaryServerInterceptor(loggingInterceptor(logger)),
),
grpc.ChainStreamInterceptor(
logging.StreamServerInterceptor(loggingInterceptor(logger)),
),
)
// Panels Service Server
panelSvr := NewPanelServer(panelService)
panelv1.RegisterPanelServiceServer(svr, &panelSvr)
// Health Check Server
healthSvr := health.NewServer()
grpc_health_v1.RegisterHealthServer(svr, healthSvr)
return &RPCServer{grpcSvr: svr}
}
func loggingInterceptor(logger zerolog.Logger) logging.Logger {
return logging.LoggerFunc(func(ctx context.Context, lvl logging.Level, msg string, fields ...any) {
logger := logger.With().Fields(fields).Logger()
switch lvl {
case logging.LevelError:
logger.Error().Msg(msg)
case logging.LevelWarn:
logger.Warn().Msg(msg)
case logging.LevelInfo:
logger.Info().Msg(msg)
case logging.LevelDebug:
logger.Debug().Msg(msg)
default:
logger.Debug().Interface("unknown-log-level", lvl).Msg(msg)
}
})
}
func (r *RPCServer) Serve() {
// Prepare the listening port.
lis, err := net.Listen("tcp", "0.0.0.0:9090")
if err != nil {
log.Panic().Err(err).Caller().Msg("failed to listen on RPC port (:9090)")
}
// Begin serving gRPC.
log.Info().Str("address", lis.Addr().String()).Msg("attempting to serve RPC...")
err = r.grpcSvr.Serve(lis)
if err != nil {
log.Panic().Err(err).Caller().Msg("failed to serve RPC")
}
}

View File

@@ -0,0 +1,126 @@
package service
import (
"context"
"github.com/hexolan/panels/panel-service/internal"
"github.com/hexolan/panels/panel-service/internal/kafka"
)
type panelService struct {
events kafka.PanelEventProducer
repo internal.PanelRepository
}
func NewPanelService(events kafka.PanelEventProducer, repo internal.PanelRepository) internal.PanelService {
return panelService{
events: events,
repo: repo,
}
}
func (srv panelService) GetPanelIdFromName(ctx context.Context, name string) (*int64, error) {
return srv.repo.GetPanelIdFromName(ctx, name)
}
func (srv panelService) CreatePanel(ctx context.Context, data internal.PanelCreate) (*internal.Panel, error) {
// Validate the data
err := data.Validate()
if err != nil {
return nil, internal.NewServiceErrorf(internal.InvalidArgumentErrorCode, "invalid argument: %s", err.Error())
}
// Create the panel
panel, err := srv.repo.CreatePanel(ctx, data)
// Dispatch panel created event
if err == nil {
srv.events.DispatchCreatedEvent(*panel)
}
return panel, err
}
func (srv panelService) GetPanel(ctx context.Context, id int64) (*internal.Panel, error) {
return srv.repo.GetPanel(ctx, id)
}
func (srv panelService) GetPanelByName(ctx context.Context, name string) (*internal.Panel, error) {
// Get the panel ID from the provided name
id, err := srv.GetPanelIdFromName(ctx, name)
if err != nil {
return nil, err
}
// Pass to service method for GetPanel (by id).
return srv.GetPanel(ctx, *id)
}
func (srv panelService) UpdatePanel(ctx context.Context, id int64, data internal.PanelUpdate) (*internal.Panel, error) {
// Validate the data.
if data == (internal.PanelUpdate{}) {
return nil, internal.NewServiceError(internal.InvalidArgumentErrorCode, "no data values provided")
}
err := data.Validate()
if err != nil {
return nil, internal.NewServiceErrorf(internal.InvalidArgumentErrorCode, "invalid argument: %s", err.Error())
}
// Perform some checks if the target is a primary panel
if id == 1 {
if data.Name != nil && *data.Name != "" {
return nil, internal.NewServiceError(internal.ForbiddenErrorCode, "cannot modify name of primary panel")
}
}
// Update the panel
panel, err := srv.repo.UpdatePanel(ctx, id, data)
// Dispatch panel updated event
if err == nil {
srv.events.DispatchUpdatedEvent(*panel)
}
return panel, err
}
func (srv panelService) UpdatePanelByName(ctx context.Context, name string, data internal.PanelUpdate) (*internal.Panel, error) {
// Get the panel ID from the provided name
id, err := srv.GetPanelIdFromName(ctx, name)
if err != nil {
return nil, err
}
// Pass to service method for UpdatePanel (by id).
return srv.UpdatePanel(ctx, *id, data)
}
func (srv panelService) DeletePanel(ctx context.Context, id int64) error {
// Ensure the target is not the primary panel
if id == 1 {
return internal.NewServiceError(internal.ForbiddenErrorCode, "cannot delete primary panel")
}
// Delete the panel.
err := srv.repo.DeletePanel(ctx, id)
// Dispatch panel deleted event
if err == nil {
srv.events.DispatchDeletedEvent(id)
}
return err
}
func (srv panelService) DeletePanelByName(ctx context.Context, name string) error {
// Get the panel ID from the provided name
id, err := srv.GetPanelIdFromName(ctx, name)
if err != nil {
return err
}
// Pass to service method for DeletePanel (by id).
return srv.DeletePanel(ctx, *id)
}