mongoStore

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2025 License: MIT Imports: 8 Imported by: 0

README

Certmagic Storage Backend for MongoDB

This library allows you to use MongoDB as key/certificate storage backend for your Certmagic-enabled HTTPS server.

How to use

Install this package

go get github.com/gumlet/certmagic-mongodb

Use it as your certmagic default storage backend.

import (
    mongoStore "github.com/gumlet/certmagic-mongodb"
    // other dependencies....
)

database := "companydb"

// Connect to MongoDB
clientOptions := options.Client().ApplyURI(config.MongoURI)
mongoClient, err := mongo.Connect(context.TODO(), clientOptions)

// pass MongoDB client and database name to storage interface.
storage, err := mongoStore.NewMongoStorage(mongoClient, database)
if err != nil {
    log.Fatal(err)
}
// tell certmagic to use this storage.
certmagic.Default.Storage = storage

This library will create 2 new collections certmagic-storage and certmagic-locks in your database and store all the required data in those collections. It will also create all required indexes.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoStorage

type MongoStorage struct {
	Collection *mongo.Collection
	Locks      *mongo.Collection
	LockTTL    time.Duration
	InstanceID string // Unique identifier for this instance
}

MongoStorage implements certmagic.Storage using MongoDB.

func NewMongoStorage

func NewMongoStorage(mongoClient *mongo.Client, database string) (*MongoStorage, error)

NewMongoStorage initializes the MongoStorage

func (*MongoStorage) Delete

func (m *MongoStorage) Delete(ctx context.Context, key string) error

Delete deletes a key

func (*MongoStorage) Exists

func (m *MongoStorage) Exists(ctx context.Context, key string) bool

Exists checks if a key exists

func (*MongoStorage) List

func (m *MongoStorage) List(ctx context.Context, prefix string, recursive bool) ([]string, error)

List lists keys prefixed by a string

func (*MongoStorage) Load

func (m *MongoStorage) Load(ctx context.Context, key string) ([]byte, error)

Load retrieves data by key

func (*MongoStorage) Lock

func (m *MongoStorage) Lock(ctx context.Context, key string) error

func (*MongoStorage) Stat

func (m *MongoStorage) Stat(ctx context.Context, key string) (certmagic.KeyInfo, error)

Stat returns file info (size and modified time)

func (*MongoStorage) Store

func (m *MongoStorage) Store(ctx context.Context, key string, value []byte) error

Store stores data in MongoDB

func (*MongoStorage) Unlock

func (m *MongoStorage) Unlock(ctx context.Context, key string) error

Jump to

Keyboard shortcuts

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