forked from mtusi2026/mtusi2026lab6
Реализация на 5
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"encoding/json"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/controller/http"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/cache/outside"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/storage"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/config"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/auth/jwtprovider"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/cache"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/encrypting"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/migrator"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/objectstore"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres/txmanager"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/rest/middleware"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/rest/router"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/telemetry"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/validator"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/attachment"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/auth"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/chat"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/outbox"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/user"
|
||||
stdhttp "net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
time.Local = time.UTC
|
||||
if err := run(); err != nil {
|
||||
slog.Error("application stopped", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run() error {
|
||||
cfg, err := config.New()
|
||||
if err != nil {
|
||||
return fmt.Errorf("load server config: %w", err)
|
||||
}
|
||||
|
||||
if len(os.Args) > 1 && os.Args[1] == "migrate" {
|
||||
cfg.Postgres.RunMigrations = true
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
|
||||
defer cancel()
|
||||
return migrator.New(cfg).Start(ctx)
|
||||
}
|
||||
name := "messenger-api"
|
||||
if len(os.Args) > 1 {
|
||||
name = "messenger-" + os.Args[1]
|
||||
}
|
||||
shutdown, err := telemetry.Init(context.Background(), name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer shutdown()
|
||||
attachmentConfig, err := config.LoadAttachment()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(os.Args) > 1 && (os.Args[1] == "worker" || os.Args[1] == "dispatcher" || os.Args[1] == "jobs" || os.Args[1] == "outbox") {
|
||||
return runPipeline(cfg, attachmentConfig, os.Args[1:])
|
||||
}
|
||||
if len(os.Args) > 1 && os.Args[1] == "storage" {
|
||||
return runStorage(cfg, attachmentConfig, os.Args[2:])
|
||||
}
|
||||
|
||||
// API processes never run migrations; the one-shot migrator owns schema changes.
|
||||
cfg.Postgres.RunMigrations = false
|
||||
var level slog.Level
|
||||
if err := level.UnmarshalText([]byte(cfg.Application.LogLevel)); err != nil {
|
||||
return err
|
||||
}
|
||||
// Logging is initialized for every process by telemetry.Init.
|
||||
instanceID := telemetry.InstanceID
|
||||
slog.Info("instance_started", "instance_id", instanceID)
|
||||
pgx := postgres.New(cfg.Postgres)
|
||||
rx := cache.New(cfg)
|
||||
postgresMigrator := migrator.New(cfg)
|
||||
defer pgx.Close()
|
||||
telemetry.ObservePool(pgx, 0)
|
||||
defer rx.Close()
|
||||
tm := txmanager.New(pgx)
|
||||
provider := jwtprovider.New(cfg)
|
||||
encryptor := encrypting.New()
|
||||
|
||||
chatsRepo := storage.NewChatsRepo(pgx)
|
||||
messageRepo := storage.NewMessagesRepo(pgx)
|
||||
refreshTokensRepo := storage.NewRefreshTokensRepo(pgx)
|
||||
userRepo := storage.NewUsersRepo(pgx)
|
||||
|
||||
chatCache := outside.NewChatCache(rx)
|
||||
|
||||
authSvc := auth.New(provider, tm, encryptor, userRepo, refreshTokensRepo)
|
||||
userSvc := user.New(encryptor, userRepo)
|
||||
chatSvc := chat.New(tm, chatsRepo, messageRepo, chatCache)
|
||||
objectStore := objectstore.New(attachmentConfig)
|
||||
attachmentSvc := attachment.New(&storage.AttachmentsRepo{Pool: pgx}, objectStore, attachmentConfig, chatSvc)
|
||||
pipelineConfig, err := config.LoadPipeline()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outboxSvc := outbox.New(&storage.OutboxRepo{Pool: pgx}, tm, nil)
|
||||
attachmentSvc.Configure(tm, outboxSvc, pipelineConfig)
|
||||
|
||||
httpRouter := router.New(
|
||||
middleware.NewAuthMiddleware(authSvc),
|
||||
middleware.Instance(instanceID),
|
||||
middleware.RequestIDMiddleware(),
|
||||
telemetry.HTTP,
|
||||
middleware.RequestTimeout(cfg.Postgres.QueryTimeout, attachmentConfig.Timeout),
|
||||
)
|
||||
httpRouter.Get("/internal/metrics", func(w stdhttp.ResponseWriter, r *stdhttp.Request) {
|
||||
stat := pgx.Stat()
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"instance_id": instanceID, "acquire_count": stat.AcquireCount(), "acquire_duration_ns": stat.AcquireDuration().Nanoseconds(), "empty_acquire_count": stat.EmptyAcquireCount(), "acquired_conns": stat.AcquiredConns(), "total_conns": stat.TotalConns(), "max_conns": stat.MaxConns()})
|
||||
})
|
||||
server := http.New(cfg, httpRouter)
|
||||
requestValidator := validator.NewValidatorImpl()
|
||||
registerRoutes(
|
||||
http.NewAuthHandler(httpRouter, authSvc),
|
||||
http.NewHealthHandler(httpRouter, server, pgx, objectStore),
|
||||
http.NewChatHandler(httpRouter, provider, requestValidator, chatSvc),
|
||||
http.NewUserHandler(httpRouter, provider, requestValidator, userSvc),
|
||||
http.NewAttachmentHandler(httpRouter, provider, attachmentSvc),
|
||||
)
|
||||
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
|
||||
if err = postgresMigrator.Start(ctx); err != nil {
|
||||
return fmt.Errorf("start postgres migrator: %w", err)
|
||||
}
|
||||
if err = server.Start(ctx); err != nil {
|
||||
return fmt.Errorf("start HTTP server: %w", err)
|
||||
}
|
||||
if err = rx.Start(ctx); err != nil {
|
||||
slog.Warn("redis unavailable at startup; continuing without cache", "error", err)
|
||||
}
|
||||
slog.Info("HTTP server started", "address", cfg.Server.BindAddress())
|
||||
|
||||
<-ctx.Done()
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), cfg.Server.ShutdownTimeout)
|
||||
defer cancel()
|
||||
if err = server.Stop(shutdownCtx); err != nil {
|
||||
return fmt.Errorf("stop HTTP server: %w", err)
|
||||
}
|
||||
if err = postgresMigrator.Close(shutdownCtx); err != nil {
|
||||
return fmt.Errorf("close postgres migrator: %w", err)
|
||||
}
|
||||
if err = rx.Close(); err != nil {
|
||||
return fmt.Errorf("close redis: %w", err)
|
||||
}
|
||||
pgx.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func registerRoutes(handlers ...http.Handler) {
|
||||
for _, handler := range handlers {
|
||||
handler.RegisterRoutes()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/broker"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/storage"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/config"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/objectstore"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres/txmanager"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/telemetry"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/attachment"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/observation"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/outbox"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"log/slog"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func runPipeline(cfg *config.Config, a *config.Attachment, args []string) error {
|
||||
c, e := config.LoadPipeline()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
pool := postgres.New(cfg.Postgres)
|
||||
defer pool.Close()
|
||||
telemetry.ObservePool(pool, c.Concurrency)
|
||||
tm := txmanager.New(pool)
|
||||
repo := &storage.AttachmentsRepo{Pool: pool}
|
||||
rabbit := &broker.Rabbit{URL: c.BrokerURL}
|
||||
ob := outbox.New(&storage.OutboxRepo{Pool: pool}, tm, rabbit)
|
||||
svc := attachment.New(repo, objectstore.New(a), a, nil)
|
||||
svc.Configure(tm, ob, c)
|
||||
ob.OnDead = svc.PublishFailed
|
||||
if args[0] == "jobs" || args[0] == "outbox" {
|
||||
if len(args) < 2 {
|
||||
return errors.New("operator action required")
|
||||
}
|
||||
fs := flag.NewFlagSet(args[1], flag.ContinueOnError)
|
||||
idText := fs.String("id", "", "job ID (attachment ID for reprocess)")
|
||||
version := fs.Int("pipeline-version", 2, "new pipeline version")
|
||||
if e = fs.Parse(args[2:]); e != nil {
|
||||
return e
|
||||
}
|
||||
if args[1] == "list" {
|
||||
jobs, e := repo.ListJobs(ctx)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(jobs)
|
||||
}
|
||||
id, e := uuid.Parse(*idText)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
switch args[1] {
|
||||
case "redeliver":
|
||||
if os.Getenv("LAB5_FAULTS") != "1" {
|
||||
return errors.New("redeliver is restricted to the explicit fault profile")
|
||||
}
|
||||
var payload []byte
|
||||
e = tm.RunInTransaction(ctx, nil, func(tx pgx.Tx) error {
|
||||
j, e := repo.JobTx(ctx, tx, id)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
payload, e = json.Marshal(j.Message)
|
||||
return e
|
||||
})
|
||||
if e == nil {
|
||||
e = rabbit.Publish(ctx, outbox.DeliveryMessage{ID: uuid.New(), AggregateID: id, Payload: payload})
|
||||
}
|
||||
case "replay":
|
||||
e = svc.Replay(ctx, id)
|
||||
case "reprocess":
|
||||
e = svc.Reprocess(ctx, id, *version)
|
||||
default:
|
||||
return errors.New("unknown operator action")
|
||||
}
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"accepted": true, "id": id})
|
||||
}
|
||||
if c.BrokerURL == "" {
|
||||
return errors.New("BROKER_URL_FILE is required")
|
||||
}
|
||||
if args[0] == "worker" {
|
||||
// Recovery continues while the consumer is disconnected or a delivery is paused.
|
||||
recoveryDone := make(chan struct{})
|
||||
defer func() { stop(); <-recoveryDone }()
|
||||
go func() {
|
||||
defer close(recoveryDone)
|
||||
tick := time.NewTicker(time.Second)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-tick.C:
|
||||
if e := svc.Recover(ctx); e != nil {
|
||||
slog.Warn("job_recovery_failed")
|
||||
}
|
||||
if e := svc.Cleanup(ctx); e != nil {
|
||||
slog.Warn("source_cleanup_failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
for ctx.Err() == nil {
|
||||
if e = rabbit.Consume(ctx, c.Concurrency, c.Prefetch, svc.Process); e != nil && ctx.Err() == nil {
|
||||
slog.Warn("consumer_reconnecting")
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(time.Second):
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
observer := &observation.Service{Repo: &storage.ObservationRepo{Pool: pool}, Publish: func(s observation.Snapshot) {
|
||||
telemetry.PublishObservation(s.Queued, s.Outbox, s.Good, s.Bad, s.Oldest, s.Locked)
|
||||
}}
|
||||
telemetry.RegisterObservation()
|
||||
nextObservation := time.Time{}
|
||||
for ctx.Err() == nil {
|
||||
if time.Now().After(nextObservation) {
|
||||
if err := observer.Observe(ctx); err != nil {
|
||||
slog.Warn("observation_unavailable")
|
||||
}
|
||||
depth, err := rabbit.Depth(ctx)
|
||||
if err == nil {
|
||||
telemetry.QueueDepth.Store(int64(depth))
|
||||
}
|
||||
nextObservation = time.Now().Add(time.Second)
|
||||
}
|
||||
_, e = ob.ProcessOnce(ctx)
|
||||
if e != nil {
|
||||
slog.Warn("dispatcher_retry")
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(100 * time.Millisecond):
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
"github.com/aws/smithy-go"
|
||||
"github.com/google/uuid"
|
||||
|
||||
"gitea.privcloud.tech/mtusi2026/internal/adapter/repository/storage"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/config"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/objectstore"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/pkg/postgres/txmanager"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/attachment"
|
||||
"gitea.privcloud.tech/mtusi2026/internal/service/outbox"
|
||||
)
|
||||
|
||||
func runStorage(cfg *config.Config, c *config.Attachment, args []string) error {
|
||||
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelWarn})))
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("storage command required")
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||
defer cancel()
|
||||
store := objectstore.New(c)
|
||||
if args[0] == "bootstrap" {
|
||||
var err error
|
||||
for i := 0; i < 60; i++ {
|
||||
_, err = store.Client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: &c.Bucket})
|
||||
var api smithy.APIError
|
||||
if err == nil || (errors.As(err, &api) && (api.ErrorCode() == "BucketAlreadyOwnedByYou" || api.ErrorCode() == "BucketAlreadyExists")) {
|
||||
if store.Ping(ctx) == nil {
|
||||
// HEAD alone can succeed before the restarted master/volume write path.
|
||||
// This constant key is outside the application's immutable originals prefix.
|
||||
key := "bootstrap/write-check"
|
||||
if store.Put(ctx, key, "application/octet-stream", strings.NewReader("ready"), 5) == nil && store.Delete(ctx, key) == nil {
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"bucket_ready": true, "write_checked": true})
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
return fmt.Errorf("storage bootstrap failed: %w", err)
|
||||
}
|
||||
if args[0] == "private-check" {
|
||||
// Unsigned requests must reach the S3 server and receive an auth failure,
|
||||
// rather than passing because a network error hid a public object.
|
||||
fs := flag.NewFlagSet("private-check", flag.ContinueOnError)
|
||||
key := fs.String("key", "", "known object key")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
client := http.Client{Timeout: 5 * time.Second, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
|
||||
resp, e := client.Get(c.Endpoint + "/" + c.Bucket + "/" + *key)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 401 && resp.StatusCode != 403 {
|
||||
return fmt.Errorf("unsigned GET returned %d", resp.StatusCode)
|
||||
}
|
||||
_, e = store.Client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: new("forbidden-" + uuid.NewString())})
|
||||
var api smithy.APIError
|
||||
if !errors.As(e, &api) || api.ErrorCode() != "AccessDenied" {
|
||||
return fmt.Errorf("API key bucket creation was not denied")
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"anonymous_status": resp.StatusCode, "api_create_bucket_denied": true})
|
||||
}
|
||||
if args[0] == "object-check" {
|
||||
fs := flag.NewFlagSet("object-check", flag.ContinueOnError)
|
||||
key := fs.String("key", "", "synthetic object key")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
head, e := store.Head(ctx, *key)
|
||||
if objectstore.Missing(e) {
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"exists": false})
|
||||
}
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"exists": true, "last_modified": head.LastModified, "size_bytes": head.ContentLength})
|
||||
}
|
||||
|
||||
pool := postgres.New(cfg.Postgres)
|
||||
defer pool.Close()
|
||||
svc := attachment.New(&storage.AttachmentsRepo{Pool: pool}, store, c, nil)
|
||||
jobs, e := config.LoadPipeline()
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
tm := txmanager.New(pool)
|
||||
svc.Configure(tm, outbox.New(&storage.OutboxRepo{Pool: pool}, tm, nil), jobs)
|
||||
switch args[0] {
|
||||
case "reconcile":
|
||||
fs := flag.NewFlagSet("reconcile", flag.ContinueOnError)
|
||||
apply := fs.Bool("apply", false, "apply safe changes")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
result, e := svc.Reconcile(ctx, *apply)
|
||||
_ = json.NewEncoder(os.Stdout).Encode(result)
|
||||
return e
|
||||
case "restore":
|
||||
fs := flag.NewFlagSet("restore", flag.ContinueOnError)
|
||||
id := fs.String("id", "", "attachment id")
|
||||
source := fs.String("source", "", "original file")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
uid, e := uuid.Parse(*id)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
if e = svc.Restore(ctx, uid, *source); e != nil {
|
||||
return e
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"restored": uid})
|
||||
case "seed":
|
||||
fs := flag.NewFlagSet("seed", flag.ContinueOnError)
|
||||
count := fs.Int("count", 1, "synthetic orphan count")
|
||||
keyOverride := fs.String("key", "", "explicit key for a single synthetic object")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
if *count < 1 || *count > 10000 {
|
||||
return fmt.Errorf("count must be 1..10000")
|
||||
}
|
||||
keys := []string{}
|
||||
for i := 0; i < *count; i++ {
|
||||
key := attachment.Prefix + uuid.NewString()
|
||||
if *keyOverride != "" {
|
||||
if *count != 1 {
|
||||
return fmt.Errorf("explicit key requires count=1")
|
||||
}
|
||||
key = *keyOverride
|
||||
}
|
||||
if e := store.Put(ctx, key, "image/png", strings.NewReader("synthetic-orphan"), 16); e != nil {
|
||||
return e
|
||||
}
|
||||
if *count == 1 {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"seeded": *count, "keys": keys})
|
||||
case "remove-object":
|
||||
fs := flag.NewFlagSet("remove-object", flag.ContinueOnError)
|
||||
id := fs.String("id", "", "synthetic attachment id")
|
||||
if e := fs.Parse(args[1:]); e != nil {
|
||||
return e
|
||||
}
|
||||
uid, e := uuid.Parse(*id)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
a, e := svc.Repo.Get(ctx, uid)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
conn, unlock, e := svc.Repo.Lock(ctx, a.Key)
|
||||
_ = conn
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer unlock()
|
||||
if e = store.Delete(ctx, a.Key); e != nil {
|
||||
return e
|
||||
}
|
||||
return json.NewEncoder(os.Stdout).Encode(map[string]any{"removed_object": uid})
|
||||
default:
|
||||
return fmt.Errorf("unknown storage command")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user