helper

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(id primitive.ObjectID, email, privateKey string) (string, error)

func ErrorResponse

func ErrorResponse(respw http.ResponseWriter, req *http.Request, statusCode int, err, msg string)

func GenerateKey

func GenerateKey() (privateKey, publicKey string)

func GetAllDocs

func GetAllDocs[T any](db *mongo.Database, col string, filter bson.M) (docs T, err error)

func GetUserFromEmail

func GetUserFromEmail(email string, db *mongo.Database) (doc model.User, err error)

func GetUserFromID

func GetUserFromID(_id primitive.ObjectID, db *mongo.Database) (doc model.User, err error)

func InsertOneDoc

func InsertOneDoc(db *mongo.Database, col string, doc any) (insertedID primitive.ObjectID, err error)

func Jsonstr

func Jsonstr(strc any) string

func MongoConnect

func MongoConnect(mconn DBInfo) (db *mongo.Database, err error)

func WriteJSON

func WriteJSON(respw http.ResponseWriter, statusCode int, content any)

Types

type DBInfo

type DBInfo struct {
	DBString string
	DBName   string
}

type Payload

type Payload struct {
	Id    primitive.ObjectID `json:"id"`
	Email string             `json:"email"`
	Exp   time.Time          `json:"exp"`
	Iat   time.Time          `json:"iat"`
	Nbf   time.Time          `json:"nbf"`
}

func Decode

func Decode(publicKey string, tokenstring string) (payload Payload, err error)

Jump to

Keyboard shortcuts

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