Spaces:
Paused
Paused
ML Intern deploy
Deploy httpSMS gateway to Hugging Face Spaces (Docker SDK): nginx :7860 -> Go API :8000, Nuxt SPA, Android APK, bootstrap-mode entrypoint
83a59ca Download api/pkg/repositories/memory_attachment_repository.go from red-kit/httpsms-gateway: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/repositories/memory_attachment_repository.go
- Command line
-
hf download hf://spaces/red-kit/httpsms-gateway/api/pkg/repositories/memory_attachment_repository.go
-
curl -L -o memory_attachment_repository.go https://huggingface.co/spaces/red-kit/httpsms-gateway/resolve/main/api/pkg/repositories/memory_attachment_repository.go
1.79 kB
| package repositories | |
| import ( | |
| "context" | |
| "fmt" | |
| "sync" | |
| "github.com/NdoleStudio/httpsms/pkg/telemetry" | |
| "github.com/NdoleStudio/stacktrace" | |
| ) | |
| // MemoryAttachmentRepository stores attachments in memory | |
| type MemoryAttachmentRepository struct { | |
| logger telemetry.Logger | |
| tracer telemetry.Tracer | |
| data sync.Map | |
| } | |
| // NewMemoryAttachmentRepository creates a new MemoryAttachmentRepository | |
| func NewMemoryAttachmentRepository( | |
| logger telemetry.Logger, | |
| tracer telemetry.Tracer, | |
| ) *MemoryAttachmentRepository { | |
| return &MemoryAttachmentRepository{ | |
| logger: logger.WithService(fmt.Sprintf("%T", &MemoryAttachmentRepository{})), | |
| tracer: tracer, | |
| } | |
| } | |
| // Upload stores attachment data at the given path | |
| func (s *MemoryAttachmentRepository) Upload(ctx context.Context, path string, data []byte, _ string) error { | |
| _, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) | |
| defer span.End() | |
| s.data.Store(path, data) | |
| ctxLogger.Info(fmt.Sprintf("stored attachment at path [%s] with size [%d]", path, len(data))) | |
| return nil | |
| } | |
| // Download retrieves attachment data from the given path | |
| func (s *MemoryAttachmentRepository) Download(ctx context.Context, path string) ([]byte, error) { | |
| _, span, _ := s.tracer.StartWithLogger(ctx, s.logger) | |
| defer span.End() | |
| value, ok := s.data.Load(path) | |
| if !ok { | |
| return nil, s.tracer.WrapErrorSpan(span, stacktrace.NewErrorWithCodef(ErrCodeNotFound, "attachment not found at path [%s]", path)) | |
| } | |
| return value.([]byte), nil | |
| } | |
| // Delete removes an attachment at the given path | |
| func (s *MemoryAttachmentRepository) Delete(ctx context.Context, path string) error { | |
| _, span, ctxLogger := s.tracer.StartWithLogger(ctx, s.logger) | |
| defer span.End() | |
| s.data.Delete(path) | |
| ctxLogger.Info(fmt.Sprintf("deleted attachment at path [%s]", path)) | |
| return nil | |
| } | |