models

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIRateLimit

func APIRateLimit(ak *APIKey) (rate.Limit, int)

func Bootstrap

func Bootstrap(
	ctx context.Context,
	name, fullName, email, password, key string,
)

Create a user and API key. No validation is done. If A User exists no further operations are done.

func CacheRateLimit

func CacheRateLimit(c *CachedSite) (rate.Limit, int)

func ChangeSiteVisibility

func ChangeSiteVisibility(ctx context.Context, site *Site, public bool)

func Check

func Check(ctx context.Context) bool

Check performs health check on the database. This make sure we can query the database

func CleanupDOmain

func CleanupDOmain(domain string) string

func CloseDB

func CloseDB(db *gorm.DB) error

func CountOwnedSites

func CountOwnedSites(ctx context.Context, uid uint64) int64

CountOwnedSites counts sites owned by the user.

func CreatePersonalAccessToken added in v0.0.13

func CreatePersonalAccessToken(ctx context.Context,
	key, name string, uid uint64, days int, scopes schema.ScopeList)

func CreateSite

func CreateSite(ctx context.Context, usr *User, domain string, public bool) bool

func Database

func Database(cfg *config.Options) string

func DeleteGoal

func DeleteGoal(ctx context.Context, gid, domain string) bool
func DeleteSharedLink(ctx context.Context, shared *SharedLink)

func DeleteSite

func DeleteSite(ctx context.Context, site *Site)

func Exists

func Exists(ctx context.Context, where func(db *gorm.DB) *gorm.DB) bool

func Get

func Get(ctx context.Context) *gorm.DB

func GetRole

func GetRole(ctx context.Context) string

func GoalName

func GoalName(g *Goal) string

func HashAPIKey

func HashAPIKey(ctx context.Context, key string) string

func HashPassword added in v0.0.11

func HashPassword(password string) string

func LOG

func LOG(ctx context.Context, err error, msg string, f ...func(*zerolog.Event) *zerolog.Event)

func NewUser

func NewUser(ctx context.Context, u *User, password, passwordConfirm string) (validation map[string]string)

func Open

func Open(path string) (*gorm.DB, error)

func PasswordMatch

func PasswordMatch(u *User, pwd string) bool

func PreloadSite

func PreloadSite(ctx context.Context, u *Site, preload ...string)

func PreloadUser

func PreloadUser(ctx context.Context, u *User, preload ...string)

func ProcessAPIKey

func ProcessAPIKey(ctx context.Context, key string) (hash, prefix string)

func QuerySitesToCache

func QuerySitesToCache(ctx context.Context, fn func(*CachedSite)) (count float64)

func SafeDomain

func SafeDomain(s *Site) string

func Set

func Set(ctx context.Context, dbs *gorm.DB) context.Context

func SetPassword

func SetPassword(ctx context.Context, pwd string) (err string)

func SetRole

func SetRole(ctx context.Context, role string) context.Context

func SetSite

func SetSite(ctx context.Context, site *Site) context.Context

func SetUser

func SetUser(ctx context.Context, usr *User) context.Context

func SharedLinkURL

func SharedLinkURL(base string, site *Site, link *SharedLink) string

func SiteHasGoals

func SiteHasGoals(ctx context.Context, domain string) bool

func UpdatePersonalAccessTokenUse added in v0.0.13

func UpdatePersonalAccessTokenUse(ctx context.Context, aid uint64)
func UpdateSharedLink(ctx context.Context, shared *SharedLink, name, password string)

func UpdateSiteStartDate

func UpdateSiteStartDate(ctx context.Context, sid uint64, start time.Time)

func ValidateGoals

func ValidateGoals(event, path string) bool

func ValidateSiteDomain

func ValidateSiteDomain(ctx context.Context, domain string) (good, bad string)

Types

type APIKey

type APIKey = schema.APIKey

func APIKeyByID

func APIKeyByID(ctx context.Context, aid uint64) (a *APIKey)

func VerifyPersonalAccessToken added in v0.0.13

func VerifyPersonalAccessToken(ctx context.Context, key string) *APIKey

type CachedSite

type CachedSite struct {
	ID              uint64
	Domain          string
	StatsStartDate  time.Time
	IngestRateLimit sql.NullFloat64
	UserID          uint64
}

type EmailVerificationCode

type EmailVerificationCode = schema.EmailVerificationCode

type Goal

type Goal = schema.Goal

func CreateGoal

func CreateGoal(ctx context.Context, domain, event, path string) *Goal

func GoalByEvent

func GoalByEvent(ctx context.Context, domain, event string) *Goal

func GoalByPage

func GoalByPage(ctx context.Context, domain, page string) *Goal

func Goals

func Goals(ctx context.Context, domain string) (o []*Goal)

type Invitation

type Invitation = schema.Invitation
type SharedLink = schema.SharedLink
func CreateSharedLink(ctx context.Context, sid uint64, name, password string) *SharedLink
func GetSharedLink(ctx context.Context, sid uint64, name string) *SharedLink

func GetSharedLinkWithSlug

func GetSharedLinkWithSlug(ctx context.Context, sid uint64, slug string) *SharedLink

type Site

type Site = schema.Site

func GetSite

func GetSite(ctx context.Context) *Site

func SiteByDomain

func SiteByDomain(ctx context.Context, domain string) *Site

func SiteFor

func SiteFor(ctx context.Context, uid uint64, domain string) *Site

type SiteOverView

type SiteOverView struct {
	Site     *Site
	Visitors uint32
}

type User

type User = schema.User

func GetUser

func GetUser(ctx context.Context) *User

func QueryUserByNameOrEmail added in v0.0.13

func QueryUserByNameOrEmail(ctx context.Context, nameOrEmail string) *User

func UserByID

func UserByID(ctx context.Context, uid uint64) (u *User)

func UserByUID

func UserByUID(ctx context.Context, uid uint64) (u *User)

Jump to

Keyboard shortcuts

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