CommonWealth

package module
v0.0.0-...-6392f1a Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2025 License: MIT Imports: 10 Imported by: 0

README

CommonWealth

A collection of code snippets to be used by a variety of microservices. By itself, it is of limited use.

Documentation

Overview

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

package CommonWealth are all of the assets that various microservices might need to share

Index

Constants

View Source
const (
	Read             = "read"
	Create           = "create"
	Update           = "update"
	Delete           = "delete"
	AFM              = "afm"
	Status           = "status"
	Database         = "database"
	Query            = "query"
	SessionDatabase  = "session"
	CompanyIndex     = 0
	ApplicationIndex = 1
	CommandIndex     = 2
)

Standard verbs subject/topics

View Source
const (
	LoginSubject      = "login"
	LogoutSubject     = "logout"
	UserNameParameter = "user_name"
)
View Source
const (
	UserSubject   = "user"
	AdminRole     = "ADMIN"
	ModeratorRole = "MODERATOR"
	UserRole      = "USER"
	BannedRole    = "BANNED"
)

UserSubject so we end up with user/create user/read, etc.

View Source
const (
	SessionTableName = "session"
)

Variables

This section is empty.

Functions

func CreateSubject

func CreateSubject(pieces []string) string

CreateSubject create a subject from a number of pieces

func DetermineDeviceClientID

func DetermineDeviceClientID() string

func GenerateHashword

func GenerateHashword(password string) (string, error)

GenerateHashword takes a password and returns an encoded string w/ random salt

func StripBrackets

func StripBrackets(value string) string

StripBrackets removes the starting and ending brackets if any

Types

type DatabaseQuery

type DatabaseQuery struct {
	Query string `json:"query"`
	Error error  `json:"error"`
}

type DatabaseResponse

type DatabaseResponse struct {
	Entries map[string]any
}

type LoginUser

type LoginUser struct {
	UserName string `json:"user_name"`
	Token    string `json:"token"`
}

LoginUser struct to define what is needed to log in a user

type NatsRegistration

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

func (*NatsRegistration) ConfigureNATsSystem

func (reg *NatsRegistration) ConfigureNATsSystem() (*nats.Conn, error)

ConfigureNATsSystem creates a nats connection and registers callbacks

func (*NatsRegistration) Subscribe

func (reg *NatsRegistration) Subscribe(nc *nats.Conn, topic NatsTopics, callback nats.MsgHandler) error

Subscribe allows users to subscribe to nats topics

type NatsTopics

type NatsTopics struct {
	Name   string `yaml:"name"`   // the name of the topic to subscribe to (subject)
	Create bool   `yaml:"create"` // the create verb if needed or not ignored if always
	Read   bool   `yaml:"read"`   // the read verb if needed or not ignored if always
	Update bool   `yaml:"update"` // the update verb if needed or not ignored if always
	Delete bool   `yaml:"delete"` // the delete verb if needed or not ignored if always
	Always bool   `yaml:"always"` // the always verb that subscribes to the given name only
}

NatsTopics are topics that will be handled by each service

type Session

type Session struct {
	SessionEntry SessionEntry `db:"session"`
}

type SessionEntry

type SessionEntry struct {
	ID     uuid.UUID `json:"id"`
	Name   string    `json:"name"`
	Value  string    `json:"value"`
	Active bool      `json:"active"`
}

type StatusData

type StatusData struct {
	ApplicationName    string `json:"app_name"`
	ApplicationHealth  int    `json:"app_health"`
	ApplicationMessage string `json:"app_msg"`
}

type User

type User struct {
	ID            uuid.UUID
	LastActivity  time.Time
	Authenticated bool
}

User is for storing session information

type UserEntry

type UserEntry struct {
	ID             uuid.UUID  `db:"id"`
	Role           string     `db:"role"`
	FirstName      string     `db:"first_name"`
	LastName       string     `db:"last_name"`
	UserName       string     `db:"user_name"`
	Email          string     `db:"email"`
	Phone          string     `db:"phone"`
	Password       string     `db:"password"`
	PasswordChange *time.Time `db:"password_change"`
	LastLogin      *time.Time `db:"last_login"`
	Created        time.Time  `db:"created"`
	Updated        time.Time  `db:"updated"`
	Active         bool       `db:"active"`
}

type WebResponse

type WebResponse struct {
	ID       uuid.UUID `json:"ID"`
	HttpCode int       `json:"code"`
}

The response to the request

Jump to

Keyboard shortcuts

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