usernamegen

package module
v0.0.0-...-76992fd Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 7 Imported by: 0

README

usernamegen

a collision-free username generator package

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Separator          string
	GeneratorBatchSize int64

	// MinAvailable is the minimum count of unused unique username
	// available in the Storage
	MinAvailable int64
	Logger       Logger
}

type Logger

type Logger interface {
	LogInfoF(msg string, args ...interface{})
	LogErrorF(err error, msg string, args ...interface{})
}

type Storage

type Storage interface {

	// SaveBatch saves a new batch of usernames into Storage.
	// It can not be ascertained that each element in names will be unique,
	// hence SaveBatch must be designed to ignore error on such conflict
	//
	// Errors are logged to Logger
	SaveBatch(ctx context.Context, names []Username) (savedCount int64)

	// FetchNewUsername from Storage
	// Note that the fetched username can not be reused
	FetchNewUsername(ctx context.Context) (string, error)
}

func UseMongoDB

func UseMongoDB(ctx context.Context, dsn string, cfg Config) Storage

type Username

type Username struct {
	Username string `bson:"username" sql:"username"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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