models

package
v0.0.0-...-450141a Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const SimilarityThreshold = 0.8

Variables

View Source
var DB *gorm.DB
View Source
var IPs []string

Functions

func CreateRoot

func CreateRoot() error

CreateRoot creates a user directly from the server

func OrderBySimilarity

func OrderBySimilarity(arr []NameSimilarity) ([]string, error)

OrderBySimilarity sorts an array of NameSimilarity objects by descending similarity and then by ascending name length.

func TrustedIPs

func TrustedIPs() ([]string, error)

TrustedIPs returns all IPs from users on the database

Types

type Log

type Log struct {
	gorm.Model
	Time    string
	Status  string
	Latency string
	IP      string
	Method  string
	Path    string
}

Log is a struct representing a log record

func (*Log) Upload

func (*Log) Upload(fileName string) error

Upload reads the log file, replaces null bytes with empty strings, then saves the logs to the database. The fileName parameter is the path to the file that contains the logs.

func (*Log) UploadLog

func (l *Log) UploadLog(ticker *time.Ticker, fileName string)

UploadLog creates a goroutine that uploads the log file content every time the given ticker is triggered. The fileName parameter is the path to the file that contains the logs.

type NameSimilarity

type NameSimilarity struct {
	Name       string
	Similarity float32
}

NameSimilarity contains a name and a Levenshtein score

func SearchSimilarNames

func SearchSimilarNames(paradigmName string, allNames []NameType, threshold float32) []NameSimilarity

SearchSimilarNames returns a slice of NameLevenshtein elements that have a similarity score higher than the given threshold to the given paradigmName

type NameType

type NameType struct {
	gorm.Model
	Name           string `gorm:"unique" json:"Name,omitempty"`
	Classification string `json:"Classification,omitempty"`
	Metaphone      string `json:"Metaphone,omitempty"`
	NameVariations string `json:"NameVariations,omitempty"`
}

NameType is a struct representing a name record

func GetAllNames

func GetAllNames() ([]NameType, error)

GetAllNames returns all non-deleted names in the database

func GetNameById

func GetNameById(id int) (*NameType, *gorm.DB, error)

GetNameById returns the name record with the given ID (non-deleted)

func GetNameByName

func GetNameByName(name string) (*NameType, error)

GetNameByName returns the name record with the given name (non-deleted)

func GetSimilarMatch

func GetSimilarMatch(name string, allNames []NameType) (*NameType, error)

GetSimilarMatch searches for a similar match for a given name in a slice of NameType.

func SearchCacheMetaphone

func SearchCacheMetaphone(metaphone string, cache []NameType) []NameType

SearchCacheMetaphone searches for all NameType objects in the cache that have a matching metaphone value and returns them as a slice

func SearchCanonicalName

func SearchCanonicalName(paradigmName string, threshold float32, allNames []NameType, matchingMetaphoneNames []NameType, nameVariations []string) (*NameType, error)

SearchCanonicalName searches for a canonical name in a list of names using a given threshold for similarity matching.

func SearchSimilarMetaphone

func SearchSimilarMetaphone(paradigmMetaphone string, allNames []NameType) []NameType

SearchSimilarMetaphone returns a slice of NameType elements that have a metaphone similar to the given paradigmMetaphone

func (*NameType) CreateName

func (n *NameType) CreateName() error

CreateName creates a new name record

func (*NameType) DeleteName

func (n *NameType) DeleteName() error

DeleteName deletes a name from the database by its ID.

func (*NameType) UpdateName

func (n *NameType) UpdateName(db *gorm.DB, updateName NameType) (NameType, error)

UpdateName updates a name from the database by its ID.

type User

type User struct {
	gorm.Model `json:"Gorm.Model"` // Use backticks for struct tags
	Email      string              `gorm:"unique" json:"Email,omitempty"`
	Password   string              `json:"Password,omitempty"`
	IP         string              `json:"IP,omitempty"`
}

User is the struct for API users

func GetAllUsers

func GetAllUsers() ([]User, error)

GetAllUsers returns all users in the database

func GetUserByEmail

func GetUserByEmail(email string) (User, error)

GetUserByEmail gets a user by their email

func (*User) CreateUser

func (u *User) CreateUser() (User, error)

CreateUser creates a new user

func (*User) DeleteUser

func (u *User) DeleteUser() (User, error)

DeleteUser deletes a user by their ID

type UserInputBody

type UserInputBody struct {
	Email    string `json:"Email,omitempty"`
	Password string `json:"Password,omitempty"`
}

UserInputBody is the struct for validation middlewares

Jump to

Keyboard shortcuts

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