Documentation
¶
Overview ¶
Package firestore provides a Firestore storage driver for Fiber. It uses cloud.google.com/go/firestore v1.14.0 for Google Cloud Firestore operations.
Key dependencies:
- cloud.google.com/go/firestore: Official Firestore Go SDK
- google.golang.org/api/option: Authentication options (ADC, service account)
- google.golang.org/grpc: gRPC communication and status codes
Index ¶
- Variables
- func LoadCredentialsFromFile(filepath string) (string, error)
- type Config
- type Storage
- func (s *Storage) Close() error
- func (s *Storage) Conn() *firestore.Client
- func (s *Storage) Delete(key string) error
- func (s *Storage) DeleteWithContext(ctx context.Context, key string) error
- func (s *Storage) Get(key string) ([]byte, error)
- func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)
- func (s *Storage) Reset() error
- func (s *Storage) ResetWithContext(ctx context.Context) error
- func (s *Storage) Set(key string, val []byte, exp time.Duration) error
- func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ Collection: "fiber_storage", RequestTimeout: 10 * time.Second, Reset: false, }
ConfigDefault is the default config
Functions ¶
func LoadCredentialsFromFile ¶
LoadCredentialsFromFile loads credentials from a file and returns as JSON string. This is a utility function for consumers of this package who need to load credentials from a file path and pass them to the Config.Credentials field.
Example:
credentials, err := firestore.LoadCredentialsFromFile("/path/to/service-account-key.json")
if err != nil {
log.Fatal(err)
}
store := firestore.New(firestore.Config{
ProjectID: "my-gcp-project",
Credentials: credentials,
})
Types ¶
type Config ¶
type Config struct {
// ProjectID is the Google Cloud project ID
// Required. Will panic if empty
ProjectID string
// Collection name where data will be stored
//
// Optional. Default is "fiber_storage"
Collection string
// CredentialsPath is the path to the service account JSON key file
// If not provided, Application Default Credentials (ADC) will be used
// Download from: Firebase Console -> Project Settings -> Service Accounts -> Generate New Private Key
// See: https://cloud.google.com/docs/authentication/application-default-credentials
//
// Optional. Default is ""
CredentialsPath string
// Credentials is a JSON string with service account credentials
// Takes precedence over CredentialsPath if both are provided
// Useful for embedding credentials or loading from environment variables
//
// Optional. Default is ""
Credentials string
// RequestTimeout is the timeout for Firestore requests
//
// Optional. Default is 10 seconds
RequestTimeout time.Duration
// Reset clears all documents in the collection on initialization
//
// Optional. Default is false
Reset bool
}
Config defines the config for Firestore storage.
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage interface that is implemented by storage providers
func NewFromConnection ¶
NewFromConnection creates a new Storage instance from an existing Firestore client
func (*Storage) DeleteWithContext ¶
DeleteWithContext deletes entry by key with context
func (*Storage) GetWithContext ¶
GetWithContext gets value by key with context
func (*Storage) ResetWithContext ¶
ResetWithContext reset all keys with context