firebase_storage

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-firebase-storage

Firebase Realtime Database storage implementation.

状态:不可用于分布式锁。 这个实现可以存取 LockInformation, 但它不声明 CapabilityCAS 与 CapabilityReliableTime,NewStorageLock 会拒绝在它上面创建锁。需要 Firebase 上跑锁时,应改用 Firebase 的 事务 API 或专门的强一致后端。

Features

  • ✅ Free tier: 100K connections/day, 1GB storage
  • ✅ No authentication required (public rules)
  • ✅ Multi-tenant isolation via tenant ID
  • ✅ REST API integration
  • ⚠️ 不能用作分布式锁后端:REST API 未使用 ETag/If-Match,UpdateWithVersion 是 先 GET 再 PUT,不满足线性一致 CAS;GetTime 返回本机时间,不是服务端时钟

Usage

import (
    firebase_storage "github.com/storage-lock/go-firebase-storage"
)

options := &firebase_storage.FirebaseStorageOptions{
    DatabaseURL: "https://your-project.firebaseio.com",
    TenantID:    "user-uuid", // for data isolation
}
storage, err := firebase_storage.NewFirebaseStorage(ctx, options)

Firebase Setup

  1. Create a Firebase project
  2. Enable Realtime Database
  3. Configure public rules:
{
  "rules": {
    ".read": true,
    ".write": true
  }
}

Security Note

This implementation uses public Firebase rules for zero-configuration usage. Anyone with the database URL can read/write data. For production use, configure Firebase Authentication and restrict rules accordingly.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFirebaseURLRequired = errors.New("firebase database URL is required")
	ErrLockNotFound        = storage_lock.ErrLockNotFound
)

Functions

This section is empty.

Types

type FirebaseStorage

type FirebaseStorage struct {
	// contains filtered or unexported fields
}

FirebaseStorage 基于 Firebase Realtime Database 的存储实现 使用 Firebase REST API,无需认证(适用于公开规则配置的数据库)

func NewFirebaseStorage

func NewFirebaseStorage(ctx context.Context, options *FirebaseStorageOptions) (*FirebaseStorage, error)

func (*FirebaseStorage) Capabilities

func (s *FirebaseStorage) Capabilities() []storage.StorageCapability

Capabilities 如实声明这个实现能提供什么。

Firebase Realtime Database 的 REST API 在这里没有用上 ETag/If-Match 条件 PUT, UpdateWithVersion 是"先 GET 再 PUT",中间存在竞态窗口,因此 **不声明 CapabilityCAS**。 GetTime 返回的是本机时间,不是可信的跨节点服务端时钟,因此 **不声明 CapabilityReliableTime**。

结果是 NewStorageLock 会拒绝在它上面创建锁,这正是期望行为:宁可不可用, 也不要拿一个会误判互斥的存储去承载分布式锁。

func (*FirebaseStorage) Close

func (s *FirebaseStorage) Close(ctx context.Context) error

func (*FirebaseStorage) CreateWithVersion

func (s *FirebaseStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error

func (*FirebaseStorage) Delete

func (s *FirebaseStorage) Delete(ctx context.Context, lockId string) error

func (*FirebaseStorage) DeleteWithVersion

func (s *FirebaseStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) error

func (*FirebaseStorage) Get

func (s *FirebaseStorage) Get(ctx context.Context, lockId string) (string, error)

func (*FirebaseStorage) GetName

func (s *FirebaseStorage) GetName() string

func (*FirebaseStorage) GetTime

func (s *FirebaseStorage) GetTime(ctx context.Context) (time.Time, error)

func (*FirebaseStorage) Init

func (s *FirebaseStorage) Init(ctx context.Context) error

func (*FirebaseStorage) List

func (*FirebaseStorage) Set

func (s *FirebaseStorage) Set(ctx context.Context, lockId string, lockInformation *storage.LockInformation) error

func (*FirebaseStorage) UpdateWithVersion

func (s *FirebaseStorage) UpdateWithVersion(ctx context.Context, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error

func (*FirebaseStorage) Watch

func (s *FirebaseStorage) Watch(ctx context.Context, lockId string) (<-chan *storage.LockInformation, error)

type FirebaseStorageOptions

type FirebaseStorageOptions struct {
	DatabaseURL string
	HTTPClient  *http.Client
	TenantID    string // 租户 ID,用于数据隔离
}

FirebaseStorageOptions 配置 Firebase 存储

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址