Compare commits

...

10 commits
v0.1.9 ... main

Author SHA1 Message Date
nquidox
80ec1a2a16 ctx fix
All checks were successful
/ Make image (push) Successful in 57s
2026-04-06 12:46:55 +03:00
nquidox
cf1d8ac531 update
All checks were successful
/ Make image (push) Successful in 59s
2026-04-05 17:59:47 +03:00
nquidox
b2222e956a addr forming refactor
All checks were successful
/ Make image (push) Successful in 58s
2026-04-02 17:58:49 +03:00
nquidox
ab473f02be send results hardened 2026-04-02 17:58:30 +03:00
nquidox
544c5348f1 insert prices change 2026-04-02 17:57:48 +03:00
nquidox
db9684debc log format 2026-04-02 17:56:40 +03:00
nquidox
fcf74df6a1 zero price query fix
All checks were successful
/ Make image (push) Successful in 58s
2026-04-01 22:08:14 +03:00
nquidox
30b336b4cf struct annotations
All checks were successful
/ Make image (push) Successful in 58s
2026-04-01 21:54:07 +03:00
nquidox
756d664be7 swagger docs update
All checks were successful
/ Make image (push) Successful in 59s
2026-04-01 18:36:03 +03:00
nquidox
cf84b598d0 debug logs 2026-04-01 18:35:08 +03:00
17 changed files with 333 additions and 106 deletions

View file

@ -319,31 +319,23 @@ const docTemplate = `{
}, },
"/merch/labels/{uuid}": { "/merch/labels/{uuid}": {
"get": { "get": {
"security": [ "description": "Получить персональные данные. Запрос данных по gRPC у сервиса авторизации.",
{
"BearerAuth": []
}
],
"description": "Получить метки товара по его uuid",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"Merch labels" "User"
],
"summary": "Получить метки товара по его uuid",
"parameters": [
{
"type": "string",
"description": "label uuid",
"name": "uuid",
"in": "path",
"required": true
}
], ],
"summary": "Получить персональные данные.",
"responses": { "responses": {
"200": { "200": {
"description": "OK" "description": "OK",
"schema": {
"$ref": "#/definitions/common.PersonalDTO"
}
},
"204": {
"description": "No Content"
}, },
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
@ -889,9 +881,6 @@ const docTemplate = `{
}, },
"delete": { "delete": {
"description": "Marks merch and all its extra data as deleted by uuid.", "description": "Marks merch and all its extra data as deleted by uuid.",
"consumes": [
"application/json"
],
"tags": [ "tags": [
"Merch" "Merch"
], ],
@ -1114,6 +1103,26 @@ const docTemplate = `{
} }
}, },
"definitions": { "definitions": {
"common.PersonalDTO": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"username": {
"type": "string"
},
"uuid": {
"type": "string"
}
}
},
"merch.DeleteZeroPrices": { "merch.DeleteZeroPrices": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -312,31 +312,23 @@
}, },
"/merch/labels/{uuid}": { "/merch/labels/{uuid}": {
"get": { "get": {
"security": [ "description": "Получить персональные данные. Запрос данных по gRPC у сервиса авторизации.",
{
"BearerAuth": []
}
],
"description": "Получить метки товара по его uuid",
"produces": [ "produces": [
"application/json" "application/json"
], ],
"tags": [ "tags": [
"Merch labels" "User"
],
"summary": "Получить метки товара по его uuid",
"parameters": [
{
"type": "string",
"description": "label uuid",
"name": "uuid",
"in": "path",
"required": true
}
], ],
"summary": "Получить персональные данные.",
"responses": { "responses": {
"200": { "200": {
"description": "OK" "description": "OK",
"schema": {
"$ref": "#/definitions/common.PersonalDTO"
}
},
"204": {
"description": "No Content"
}, },
"400": { "400": {
"description": "Bad Request", "description": "Bad Request",
@ -882,9 +874,6 @@
}, },
"delete": { "delete": {
"description": "Marks merch and all its extra data as deleted by uuid.", "description": "Marks merch and all its extra data as deleted by uuid.",
"consumes": [
"application/json"
],
"tags": [ "tags": [
"Merch" "Merch"
], ],
@ -1107,6 +1096,26 @@
} }
}, },
"definitions": { "definitions": {
"common.PersonalDTO": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"name": {
"type": "string"
},
"surname": {
"type": "string"
},
"username": {
"type": "string"
},
"uuid": {
"type": "string"
}
}
},
"merch.DeleteZeroPrices": { "merch.DeleteZeroPrices": {
"type": "object", "type": "object",
"properties": { "properties": {

View file

@ -1,5 +1,18 @@
basePath: /api/v2 basePath: /api/v2
definitions: definitions:
common.PersonalDTO:
properties:
email:
type: string
name:
type: string
surname:
type: string
username:
type: string
uuid:
type: string
type: object
merch.DeleteZeroPrices: merch.DeleteZeroPrices:
properties: properties:
id: id:
@ -200,8 +213,6 @@ info:
paths: paths:
/merch/{uuid}: /merch/{uuid}:
delete: delete:
consumes:
- application/json
description: Marks merch and all its extra data as deleted by uuid. description: Marks merch and all its extra data as deleted by uuid.
parameters: parameters:
- description: merch uuid - description: merch uuid
@ -456,18 +467,16 @@ paths:
tags: tags:
- Merch labels - Merch labels
get: get:
description: Получить метки товара по его uuid description: Получить персональные данные. Запрос данных по gRPC у сервиса авторизации.
parameters:
- description: label uuid
in: path
name: uuid
required: true
type: string
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: OK description: OK
schema:
$ref: '#/definitions/common.PersonalDTO'
"204":
description: No Content
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
@ -480,11 +489,9 @@ paths:
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/responses.InternalServerError' $ref: '#/definitions/responses.InternalServerError'
security: summary: Получить персональные данные.
- BearerAuth: []
summary: Получить метки товара по его uuid
tags: tags:
- Merch labels - User
put: put:
consumes: consumes:
- application/json - application/json

View file

@ -85,7 +85,8 @@ func New(ctx context.Context, cfg config.Config) *App {
newApp.modules = append(newApp.modules, m) newApp.modules = append(newApp.modules, m)
newApp.tasker = task.New(task.Deps{ newApp.tasker = task.New(task.Deps{
Addr: "", Host: cfg.TasksSource.Host,
Port: cfg.TasksSource.Port,
MerchProvider: m, MerchProvider: m,
}) })

View file

@ -52,14 +52,13 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) {
errVal = fmt.Sprintf("%v\n", errVal) errVal = fmt.Sprintf("%v\n", errVal)
} }
fieldsLine := "| params: " fieldsLine := "\n"
fields := entry.Data fields := entry.Data
if fields != nil { if len(fields) > 0 {
fieldsLine = "| params: "
for key, val := range fields { for key, val := range fields {
fieldsLine += fmt.Sprintf("\t%v=%v ", key, val) fieldsLine += fmt.Sprintf("\t%v=%v ", key, val)
} }
} else {
fieldsLine = "\n"
} }
cyanCode := f.getLevelColor(logrus.TraceLevel) cyanCode := f.getLevelColor(logrus.TraceLevel)

View file

@ -12,9 +12,9 @@ type Result struct {
} }
type PersonalDTO struct { type PersonalDTO struct {
Uuid string Uuid string `json:"uuid"`
Email string Email string `json:"email"`
Username string Username string `json:"username"`
Name string Name string `json:"name"`
Surname string Surname string `json:"surname"`
} }

View file

@ -2,6 +2,7 @@ package merch
import ( import (
"context" "context"
log "github.com/sirupsen/logrus"
"merch-api/internal/common" "merch-api/internal/common"
"merch-api/pkg/utils" "merch-api/pkg/utils"
) )
@ -30,6 +31,7 @@ func (p *provider) GetTasks(ctx context.Context) ([]common.Task, error) {
} }
func (p *provider) InsertPrices(ctx context.Context, rawPrices []common.Result) error { func (p *provider) InsertPrices(ctx context.Context, rawPrices []common.Result) error {
log.WithField("payload", rawPrices).Debugf("%v Inserting prices", providerLogHeader)
if rawPrices == nil || len(rawPrices) == 0 { if rawPrices == nil || len(rawPrices) == 0 {
logDebug(providerLogHeader, "no prices given") logDebug(providerLogHeader, "no prices given")
return nil return nil
@ -56,15 +58,13 @@ func (p *provider) InsertPrices(ctx context.Context, rawPrices []common.Result)
var insertPrices []Price var insertPrices []Price
for _, rawPrice := range rawPrices { for _, rawPrice := range rawPrices {
insertPrices = append(insertPrices, Price{ insertPrices = append(insertPrices, Price{
CreatedAt: now,
UpdatedAt: p.utils.NullTimeFromNow(now),
MerchId: uuidMap[rawPrice.MerchUuid], MerchId: uuidMap[rawPrice.MerchUuid],
OriginId: originIds[rawPrice.OriginName], OriginId: originIds[rawPrice.OriginName],
Price: int(rawPrice.Price), Price: int(rawPrice.Price),
}) })
} }
if err = p.service.repo.insertPrices(ctx, insertPrices); err != nil { if err = p.service.repo.insertPrices(ctx, now, p.utils.NullTimeFromNow(now), insertPrices); err != nil {
logErr(serviceLogHeader, err) logErr(serviceLogHeader, err)
return err return err
} }

View file

@ -170,7 +170,7 @@ func (r *repo) getMerchUuidMap(ctx context.Context, merchUuids []string) (map[st
return nil, err return nil, err
} }
var merchUuidMap map[string]int64 merchUuidMap := make(map[string]int64)
for rows.Next() { for rows.Next() {
var ( var (
uuid string uuid string

View file

@ -8,7 +8,7 @@ import (
) )
type Prices interface { type Prices interface {
insertPrices(ctx context.Context, prices []Price) error insertPrices(ctx context.Context, now time.Time, updatedAt sql.NullTime, prices []Price) error
getPricesWithDays(ctx context.Context, userId int64, days time.Time) ([]Price, error) getPricesWithDays(ctx context.Context, userId int64, days time.Time) ([]Price, error)
getDistinctPrices(ctx context.Context, userId int64, merchUuid string, days time.Time) ([]Price, error) getDistinctPrices(ctx context.Context, userId int64, merchUuid string, days time.Time) ([]Price, error)
@ -17,7 +17,7 @@ type Prices interface {
deleteZeroPrices(ctx context.Context, userId int64, now sql.NullTime, list []int64) error deleteZeroPrices(ctx context.Context, userId int64, now sql.NullTime, list []int64) error
} }
func (r *repo) insertPrices(ctx context.Context, prices []Price) error { func (r *repo) insertPrices(ctx context.Context, now time.Time, updatedAt sql.NullTime, prices []Price) error {
q := ` q := `
INSERT INTO merch_prices (created_at, updated_at, merch_id, origin_id, price) INSERT INTO merch_prices (created_at, updated_at, merch_id, origin_id, price)
SELECT $1, $2, src.merch_id, src.origin_id, src.price SELECT $1, $2, src.merch_id, src.origin_id, src.price
@ -40,7 +40,7 @@ func (r *repo) insertPrices(ctx context.Context, prices []Price) error {
priceValues = append(priceValues, price.Price) priceValues = append(priceValues, price.Price)
} }
_, err := r.db.Exec(ctx, q, merchIds, originIds, priceValues) _, err := r.db.Exec(ctx, q, now, updatedAt, merchIds, originIds, priceValues)
if err != nil { if err != nil {
return err return err
} }
@ -127,14 +127,14 @@ func (r *repo) getZeroPrices(ctx context.Context, userId int64) ([]ZeroPrice, er
q := ` q := `
WITH price_with_neighbors AS ( WITH price_with_neighbors AS (
SELECT SELECT
p.id, p.created_at, p.merch_id, p.price, p.origin_id, m.name, p.id, p.created_at, p.merch_id, p.price, p.origin_id, m.name, m.merch_uuid,
LAG(price) OVER (PARTITION BY p.merch_id, p.origin_id ORDER BY p.created_at, p.id) AS prev_price, LAG(price) OVER (PARTITION BY p.merch_id, p.origin_id ORDER BY p.created_at, p.id) AS prev_price,
LEAD(price) OVER (PARTITION BY p.merch_id, p.origin_id ORDER BY p.created_at, p.id) AS next_price LEAD(price) OVER (PARTITION BY p.merch_id, p.origin_id ORDER BY p.created_at, p.id) AS next_price
FROM merch_prices AS p FROM merch_prices AS p
JOIN merch as m ON m.id = p.merch_id JOIN merch as m ON m.id = p.merch_id
WHERE p.deleted_at IS NULL WHERE p.deleted_at IS NULL
AND m.deleted_at IS NULL AND m.deleted_at IS NULL
AND m.user_id = 3) AND m.user_id = $1)
SELECT SELECT
pwn.id, pwn.created_at, pwn.merch_uuid, pwn.name, mo.name pwn.id, pwn.created_at, pwn.merch_uuid, pwn.name, mo.name

View file

@ -17,7 +17,8 @@ type Handler struct {
} }
type Deps struct { type Deps struct {
Addr string Host string
Port string
MerchProvider common.MerchProvider MerchProvider common.MerchProvider
} }
@ -25,7 +26,7 @@ func New(deps Deps) *Handler {
srv := grpc.NewServer() srv := grpc.NewServer()
handler := &Handler{ handler := &Handler{
addr: deps.Addr, addr: net.JoinHostPort(deps.Host, deps.Port),
service: newService(deps.MerchProvider), service: newService(deps.MerchProvider),
} }
@ -36,6 +37,7 @@ func New(deps Deps) *Handler {
} }
func (h *Handler) Serve() error { func (h *Handler) Serve() error {
log.WithField("addr", h.addr).Debugf("%v Serving tasks", pkgLogHeader)
listener, err := net.Listen("tcp", h.addr) listener, err := net.Listen("tcp", h.addr)
if err != nil { if err != nil {
log.WithError(err).Errorf("%v Listner failure", pkgLogHeader) log.WithError(err).Errorf("%v Listner failure", pkgLogHeader)

View file

@ -1,11 +1,13 @@
package task package task
import ( import (
"context"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/emptypb"
"io" "io"
"merch-api/internal/common" "merch-api/internal/common"
tt "merch-api/pkg/taskTransport/v1" tt "merch-api/pkg/taskTransport/v1"
"sync"
"time" "time"
) )
@ -21,9 +23,12 @@ func newService(mp common.MerchProvider) *service {
} }
func (s *service) RequestTasks(_ *emptypb.Empty, stream tt.TaskProcessor_RequestTasksServer) error { func (s *service) RequestTasks(_ *emptypb.Empty, stream tt.TaskProcessor_RequestTasksServer) error {
tasks, err := s.merchProvider.GetTasks(stream.Context()) ctx, cancel := context.WithCancel(context.Background())
tasks, err := s.merchProvider.GetTasks(ctx)
if err != nil { if err != nil {
log.WithError(err).Errorf("%v Failed to get tasks", pkgLogHeader) log.WithError(err).Errorf("%v Failed to get tasks", pkgLogHeader)
cancel()
return err return err
} }
@ -33,31 +38,46 @@ func (s *service) RequestTasks(_ *emptypb.Empty, stream tt.TaskProcessor_Request
Origins: task.Origins, Origins: task.Origins,
}); err != nil { }); err != nil {
log.WithError(err).Errorf("%v Failed to send tasks", pkgLogHeader) log.WithError(err).Errorf("%v Failed to send tasks", pkgLogHeader)
cancel()
return err return err
} }
} }
cancel()
return nil return nil
} }
func (s *service) SendResults(stream tt.TaskProcessor_SendResultsServer) error { func (s *service) SendResults(stream tt.TaskProcessor_SendResultsServer) error {
ctx, cancel := context.WithCancel(context.Background())
ticker := time.NewTicker(5 * time.Second) ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop() defer ticker.Stop()
mu := &sync.Mutex{}
batch := make([]common.Result, 0) batch := make([]common.Result, 0)
done := make(chan struct{})
stop := make(chan struct{})
var wg sync.WaitGroup
wg.Add(1)
go func() { go func() {
for { for {
select { select {
case <-done: case <-ctx.Done():
return return
case <-ticker.C: case <-ticker.C:
if len(batch) > 0 { mu.Lock()
err := s.merchProvider.InsertPrices(stream.Context(), batch) if len(batch) == 0 {
if err != nil { mu.Unlock()
log.WithError(err).Errorf("%v Failed to batch insert result", pkgLogHeader) continue
} }
toInsert := make([]common.Result, len(batch))
copy(toInsert, batch)
batch = batch[:0]
mu.Unlock()
if err := s.merchProvider.InsertPrices(ctx, toInsert); err != nil {
log.WithError(err).Errorf("%v Failed to batch insert result", pkgLogHeader)
} }
} }
} }
@ -72,28 +92,36 @@ func (s *service) SendResults(stream tt.TaskProcessor_SendResultsServer) error {
if err != nil { if err != nil {
log.WithError(err).Errorf("%v Failed to receive", pkgLogHeader) log.WithError(err).Errorf("%v Failed to receive", pkgLogHeader)
cancel()
return err return err
} }
mu.Lock()
batch = append(batch, common.Result{ batch = append(batch, common.Result{
MerchUuid: response.MerchUuid, MerchUuid: response.MerchUuid,
OriginName: response.OriginName, OriginName: response.OriginName,
Price: response.Price, Price: response.Price,
}) })
mu.Unlock()
} }
close(done) close(stop)
if len(batch) > 0 { wg.Wait()
err := s.merchProvider.InsertPrices(stream.Context(), batch)
mu.Lock()
finalBatch := make([]common.Result, len(batch))
copy(finalBatch, batch)
mu.Unlock()
if len(finalBatch) > 0 {
err := s.merchProvider.InsertPrices(ctx, finalBatch)
if err != nil { if err != nil {
log.WithError(err).Errorf("%v Failed to batch insert last data", pkgLogHeader) log.WithError(err).Errorf("%v Failed to batch insert last data", pkgLogHeader)
cancel()
return err return err
} }
} }
if err := stream.SendAndClose(&emptypb.Empty{}); err != nil { cancel()
return err return stream.SendAndClose(&emptypb.Empty{})
}
return nil
} }

View file

@ -130,7 +130,7 @@ func (co *controller) me(c *gin.Context) {
// @Tags User // @Tags User
// @Produce json // @Produce json
// @Success 200 {object} common.PersonalDTO // @Success 200 {object} common.PersonalDTO
// @Success 204 {object} // @Success 204
// @Failure 400 {object} responses.BadRequest // @Failure 400 {object} responses.BadRequest
// @Failure 401 {object} responses.Unauthorized // @Failure 401 {object} responses.Unauthorized
// @Failure 500 {object} responses.InternalServerError // @Failure 500 {object} responses.InternalServerError

View file

@ -3,10 +3,13 @@ package user
import ( import (
"context" "context"
"errors" "errors"
log "github.com/sirupsen/logrus"
"merch-api/internal/common" "merch-api/internal/common"
"merch-api/pkg/utils" "merch-api/pkg/utils"
) )
const serviceLogHeader string = "service |"
type service struct { type service struct {
repo Repository repo Repository
utils utils.Utils utils utils.Utils
@ -56,6 +59,7 @@ func (s *service) getPersonalData(ctx context.Context, userUuid string) (*common
if userUuid == "" { if userUuid == "" {
return nil, errors.New("user uuid is empty") return nil, errors.New("user uuid is empty")
} }
log.WithField("user_uuid", userUuid).Debugf("%v %v get personal data", pkgLogHeader, serviceLogHeader)
return s.authDP.GetPersonalData(ctx, userUuid) return s.authDP.GetPersonalData(ctx, userUuid)
} }

View file

@ -3,11 +3,14 @@ package authCheck
import ( import (
"context" "context"
"errors" "errors"
log "github.com/sirupsen/logrus"
"merch-api/internal/common" "merch-api/internal/common"
verifyV1 "merch-api/pkg/verify/v1" verifyV1 "merch-api/pkg/verify/v1"
"time" "time"
) )
const serviceLogHeader = "service |"
type service struct { type service struct {
client verifyV1.AuthServiceClient client verifyV1.AuthServiceClient
timeout time.Duration timeout time.Duration
@ -49,6 +52,11 @@ func (s *service) GetPersonalData(ctx context.Context, userUuid string) (*common
runCtx, cancel := context.WithTimeout(ctx, s.timeout) runCtx, cancel := context.WithTimeout(ctx, s.timeout)
defer cancel() defer cancel()
log.WithFields(log.Fields{
"userUuid": userUuid,
"serviceId": s.serviceId,
}).Debugf("%v %v get personal data")
response, err := s.client.GetPersonalInfo(runCtx, &verifyV1.PersonalRequest{ response, err := s.client.GetPersonalInfo(runCtx, &verifyV1.PersonalRequest{
UserUuid: userUuid, UserUuid: userUuid,
ServiceId: s.serviceId, ServiceId: s.serviceId,

View file

@ -9,6 +9,7 @@ package externalRegV1
import ( import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl" protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect" reflect "reflect"
sync "sync" sync "sync"
unsafe "unsafe" unsafe "unsafe"
@ -29,6 +30,7 @@ type RegistrationRequest struct {
ServiceEndCode int32 `protobuf:"varint,4,opt,name=service_end_code,json=serviceEndCode,proto3" json:"service_end_code,omitempty"` ServiceEndCode int32 `protobuf:"varint,4,opt,name=service_end_code,json=serviceEndCode,proto3" json:"service_end_code,omitempty"`
Secret string `protobuf:"bytes,5,opt,name=secret,proto3" json:"secret,omitempty"` Secret string `protobuf:"bytes,5,opt,name=secret,proto3" json:"secret,omitempty"`
Status string `protobuf:"bytes,6,opt,name=status,proto3" json:"status,omitempty"` Status string `protobuf:"bytes,6,opt,name=status,proto3" json:"status,omitempty"`
ServiceUrl string `protobuf:"bytes,7,opt,name=service_url,json=serviceUrl,proto3" json:"service_url,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -105,10 +107,18 @@ func (x *RegistrationRequest) GetStatus() string {
return "" return ""
} }
func (x *RegistrationRequest) GetServiceUrl() string {
if x != nil {
return x.ServiceUrl
}
return ""
}
type RegistrationResponse struct { type RegistrationResponse struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
ServiceId int32 `protobuf:"varint,1,opt,name=service_id,json=serviceId,proto3" json:"service_id,omitempty"` ServiceId int32 `protobuf:"varint,1,opt,name=service_id,json=serviceId,proto3" json:"service_id,omitempty"`
AlreadyRegistered bool `protobuf:"varint,2,opt,name=already_registered,json=alreadyRegistered,proto3" json:"already_registered,omitempty"` AlreadyRegistered bool `protobuf:"varint,2,opt,name=already_registered,json=alreadyRegistered,proto3" json:"already_registered,omitempty"`
ServiceUrl string `protobuf:"bytes,3,opt,name=service_url,json=serviceUrl,proto3" json:"service_url,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
} }
@ -157,24 +167,119 @@ func (x *RegistrationResponse) GetAlreadyRegistered() bool {
return false return false
} }
func (x *RegistrationResponse) GetServiceUrl() string {
if x != nil {
return x.ServiceUrl
}
return ""
}
type UpdateRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description,proto3" json:"description,omitempty"`
Status string `protobuf:"bytes,3,opt,name=status,proto3" json:"status,omitempty"`
ServiceUrl string `protobuf:"bytes,4,opt,name=service_url,json=serviceUrl,proto3" json:"service_url,omitempty"`
ServiceCode int32 `protobuf:"varint,5,opt,name=service_code,json=serviceCode,proto3" json:"service_code,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *UpdateRequest) Reset() {
*x = UpdateRequest{}
mi := &file_proto_serviceRegistration_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *UpdateRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpdateRequest) ProtoMessage() {}
func (x *UpdateRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_serviceRegistration_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 UpdateRequest.ProtoReflect.Descriptor instead.
func (*UpdateRequest) Descriptor() ([]byte, []int) {
return file_proto_serviceRegistration_proto_rawDescGZIP(), []int{2}
}
func (x *UpdateRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *UpdateRequest) GetDescription() string {
if x != nil {
return x.Description
}
return ""
}
func (x *UpdateRequest) GetStatus() string {
if x != nil {
return x.Status
}
return ""
}
func (x *UpdateRequest) GetServiceUrl() string {
if x != nil {
return x.ServiceUrl
}
return ""
}
func (x *UpdateRequest) GetServiceCode() int32 {
if x != nil {
return x.ServiceCode
}
return 0
}
var File_proto_serviceRegistration_proto protoreflect.FileDescriptor var File_proto_serviceRegistration_proto protoreflect.FileDescriptor
const file_proto_serviceRegistration_proto_rawDesc = "" + const file_proto_serviceRegistration_proto_rawDesc = "" +
"\n" + "\n" +
"\x1fproto/serviceRegistration.proto\x12\x11auth.registration\"\xc8\x01\n" + "\x1fproto/serviceRegistration.proto\x12\x11auth.registration\x1a\x1bgoogle/protobuf/empty.proto\"\xe9\x01\n" +
"\x13RegistrationRequest\x12\x12\n" + "\x13RegistrationRequest\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12 \n" + "\x04name\x18\x01 \x01(\tR\x04name\x12 \n" +
"\vdescription\x18\x02 \x01(\tR\vdescription\x12!\n" + "\vdescription\x18\x02 \x01(\tR\vdescription\x12!\n" +
"\fservice_code\x18\x03 \x01(\x05R\vserviceCode\x12(\n" + "\fservice_code\x18\x03 \x01(\x05R\vserviceCode\x12(\n" +
"\x10service_end_code\x18\x04 \x01(\x05R\x0eserviceEndCode\x12\x16\n" + "\x10service_end_code\x18\x04 \x01(\x05R\x0eserviceEndCode\x12\x16\n" +
"\x06secret\x18\x05 \x01(\tR\x06secret\x12\x16\n" + "\x06secret\x18\x05 \x01(\tR\x06secret\x12\x16\n" +
"\x06status\x18\x06 \x01(\tR\x06status\"d\n" + "\x06status\x18\x06 \x01(\tR\x06status\x12\x1f\n" +
"\vservice_url\x18\a \x01(\tR\n" +
"serviceUrl\"\x85\x01\n" +
"\x14RegistrationResponse\x12\x1d\n" + "\x14RegistrationResponse\x12\x1d\n" +
"\n" + "\n" +
"service_id\x18\x01 \x01(\x05R\tserviceId\x12-\n" + "service_id\x18\x01 \x01(\x05R\tserviceId\x12-\n" +
"\x12already_registered\x18\x02 \x01(\bR\x11alreadyRegistered2\x81\x01\n" + "\x12already_registered\x18\x02 \x01(\bR\x11alreadyRegistered\x12\x1f\n" +
"\vservice_url\x18\x03 \x01(\tR\n" +
"serviceUrl\"\xa1\x01\n" +
"\rUpdateRequest\x12\x12\n" +
"\x04name\x18\x01 \x01(\tR\x04name\x12 \n" +
"\vdescription\x18\x02 \x01(\tR\vdescription\x12\x16\n" +
"\x06status\x18\x03 \x01(\tR\x06status\x12\x1f\n" +
"\vservice_url\x18\x04 \x01(\tR\n" +
"serviceUrl\x12!\n" +
"\fservice_code\x18\x05 \x01(\x05R\vserviceCode2\xc5\x01\n" +
"\x14ExternalRegistration\x12i\n" + "\x14ExternalRegistration\x12i\n" +
"\x16AuthenticateOrRegister\x12&.auth.registration.RegistrationRequest\x1a'.auth.registration.RegistrationResponseB,Z*/pkg/externalRegistration/v1;externalRegV1b\x06proto3" "\x16AuthenticateOrRegister\x12&.auth.registration.RegistrationRequest\x1a'.auth.registration.RegistrationResponse\x12B\n" +
"\x06Update\x12 .auth.registration.UpdateRequest\x1a\x16.google.protobuf.EmptyB,Z*/pkg/externalRegistration/v1;externalRegV1b\x06proto3"
var ( var (
file_proto_serviceRegistration_proto_rawDescOnce sync.Once file_proto_serviceRegistration_proto_rawDescOnce sync.Once
@ -188,16 +293,20 @@ func file_proto_serviceRegistration_proto_rawDescGZIP() []byte {
return file_proto_serviceRegistration_proto_rawDescData return file_proto_serviceRegistration_proto_rawDescData
} }
var file_proto_serviceRegistration_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_proto_serviceRegistration_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_proto_serviceRegistration_proto_goTypes = []any{ var file_proto_serviceRegistration_proto_goTypes = []any{
(*RegistrationRequest)(nil), // 0: auth.registration.RegistrationRequest (*RegistrationRequest)(nil), // 0: auth.registration.RegistrationRequest
(*RegistrationResponse)(nil), // 1: auth.registration.RegistrationResponse (*RegistrationResponse)(nil), // 1: auth.registration.RegistrationResponse
(*UpdateRequest)(nil), // 2: auth.registration.UpdateRequest
(*emptypb.Empty)(nil), // 3: google.protobuf.Empty
} }
var file_proto_serviceRegistration_proto_depIdxs = []int32{ var file_proto_serviceRegistration_proto_depIdxs = []int32{
0, // 0: auth.registration.ExternalRegistration.AuthenticateOrRegister:input_type -> auth.registration.RegistrationRequest 0, // 0: auth.registration.ExternalRegistration.AuthenticateOrRegister:input_type -> auth.registration.RegistrationRequest
1, // 1: auth.registration.ExternalRegistration.AuthenticateOrRegister:output_type -> auth.registration.RegistrationResponse 2, // 1: auth.registration.ExternalRegistration.Update:input_type -> auth.registration.UpdateRequest
1, // [1:2] is the sub-list for method output_type 1, // 2: auth.registration.ExternalRegistration.AuthenticateOrRegister:output_type -> auth.registration.RegistrationResponse
0, // [0:1] is the sub-list for method input_type 3, // 3: auth.registration.ExternalRegistration.Update:output_type -> google.protobuf.Empty
2, // [2:4] is the sub-list for method output_type
0, // [0:2] 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 type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
@ -214,7 +323,7 @@ func file_proto_serviceRegistration_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(), GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_serviceRegistration_proto_rawDesc), len(file_proto_serviceRegistration_proto_rawDesc)), RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_serviceRegistration_proto_rawDesc), len(file_proto_serviceRegistration_proto_rawDesc)),
NumEnums: 0, NumEnums: 0,
NumMessages: 2, NumMessages: 3,
NumExtensions: 0, NumExtensions: 0,
NumServices: 1, NumServices: 1,
}, },

View file

@ -11,6 +11,7 @@ import (
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" 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 // This is a compile-time assertion to ensure that this generated file
@ -20,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9
const ( const (
ExternalRegistration_AuthenticateOrRegister_FullMethodName = "/auth.registration.ExternalRegistration/AuthenticateOrRegister" ExternalRegistration_AuthenticateOrRegister_FullMethodName = "/auth.registration.ExternalRegistration/AuthenticateOrRegister"
ExternalRegistration_Update_FullMethodName = "/auth.registration.ExternalRegistration/Update"
) )
// ExternalRegistrationClient is the client API for ExternalRegistration service. // ExternalRegistrationClient is the client API for ExternalRegistration service.
@ -27,6 +29,7 @@ const (
// 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. // 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 ExternalRegistrationClient interface { type ExternalRegistrationClient interface {
AuthenticateOrRegister(ctx context.Context, in *RegistrationRequest, opts ...grpc.CallOption) (*RegistrationResponse, error) AuthenticateOrRegister(ctx context.Context, in *RegistrationRequest, opts ...grpc.CallOption) (*RegistrationResponse, error)
Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
} }
type externalRegistrationClient struct { type externalRegistrationClient struct {
@ -47,11 +50,22 @@ func (c *externalRegistrationClient) AuthenticateOrRegister(ctx context.Context,
return out, nil return out, nil
} }
func (c *externalRegistrationClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, ExternalRegistration_Update_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
// ExternalRegistrationServer is the server API for ExternalRegistration service. // ExternalRegistrationServer is the server API for ExternalRegistration service.
// All implementations must embed UnimplementedExternalRegistrationServer // All implementations must embed UnimplementedExternalRegistrationServer
// for forward compatibility. // for forward compatibility.
type ExternalRegistrationServer interface { type ExternalRegistrationServer interface {
AuthenticateOrRegister(context.Context, *RegistrationRequest) (*RegistrationResponse, error) AuthenticateOrRegister(context.Context, *RegistrationRequest) (*RegistrationResponse, error)
Update(context.Context, *UpdateRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedExternalRegistrationServer() mustEmbedUnimplementedExternalRegistrationServer()
} }
@ -65,6 +79,9 @@ type UnimplementedExternalRegistrationServer struct{}
func (UnimplementedExternalRegistrationServer) AuthenticateOrRegister(context.Context, *RegistrationRequest) (*RegistrationResponse, error) { func (UnimplementedExternalRegistrationServer) AuthenticateOrRegister(context.Context, *RegistrationRequest) (*RegistrationResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method AuthenticateOrRegister not implemented") return nil, status.Errorf(codes.Unimplemented, "method AuthenticateOrRegister not implemented")
} }
func (UnimplementedExternalRegistrationServer) Update(context.Context, *UpdateRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (UnimplementedExternalRegistrationServer) mustEmbedUnimplementedExternalRegistrationServer() {} func (UnimplementedExternalRegistrationServer) mustEmbedUnimplementedExternalRegistrationServer() {}
func (UnimplementedExternalRegistrationServer) testEmbeddedByValue() {} func (UnimplementedExternalRegistrationServer) testEmbeddedByValue() {}
@ -104,6 +121,24 @@ func _ExternalRegistration_AuthenticateOrRegister_Handler(srv interface{}, ctx c
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _ExternalRegistration_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ExternalRegistrationServer).Update(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ExternalRegistration_Update_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ExternalRegistrationServer).Update(ctx, req.(*UpdateRequest))
}
return interceptor(ctx, in, info, handler)
}
// ExternalRegistration_ServiceDesc is the grpc.ServiceDesc for ExternalRegistration service. // ExternalRegistration_ServiceDesc is the grpc.ServiceDesc for ExternalRegistration service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
@ -115,6 +150,10 @@ var ExternalRegistration_ServiceDesc = grpc.ServiceDesc{
MethodName: "AuthenticateOrRegister", MethodName: "AuthenticateOrRegister",
Handler: _ExternalRegistration_AuthenticateOrRegister_Handler, Handler: _ExternalRegistration_AuthenticateOrRegister_Handler,
}, },
{
MethodName: "Update",
Handler: _ExternalRegistration_Update_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "proto/serviceRegistration.proto", Metadata: "proto/serviceRegistration.proto",

View file

@ -1,4 +1,5 @@
syntax = "proto3"; syntax = "proto3";
import "google/protobuf/empty.proto";
package auth.registration; package auth.registration;
option go_package = "/pkg/externalRegistration/v1;externalRegV1"; option go_package = "/pkg/externalRegistration/v1;externalRegV1";
@ -10,13 +11,24 @@ message RegistrationRequest {
int32 service_end_code = 4; int32 service_end_code = 4;
string secret = 5; string secret = 5;
string status = 6; string status = 6;
string service_url = 7;
} }
message RegistrationResponse { message RegistrationResponse {
int32 service_id = 1; int32 service_id = 1;
bool already_registered = 2; bool already_registered = 2;
string service_url = 3;
}
message UpdateRequest {
string name = 1;
string description = 2;
string status = 3;
string service_url = 4;
int32 service_code = 5;
} }
service ExternalRegistration { service ExternalRegistration {
rpc AuthenticateOrRegister (RegistrationRequest) returns (RegistrationResponse); rpc AuthenticateOrRegister (RegistrationRequest) returns (RegistrationResponse);
rpc Update (UpdateRequest) returns (google.protobuf.Empty);
} }