Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultAvatar is the default avatar image URL DefaultAvatar = img.SignImageURL("https://cdn.twibber.xyz/avatars/default.webp") // DefaultBanner is the default banner image URL DefaultBanner = img.SignImageURL("https://cdn.twibber.xyz/banners/default.webp") )
var Models = []any{ &User{}, &Connection{}, &Session{}, &Post{}, &Like{}, &Follow{}, }
Functions ¶
This section is empty.
Types ¶
type BaseModel ¶
type BaseModel struct {
ID string `gorm:"primaryKey" json:"id"` // ID is the primary key.
Timestamps // Timestamps for creation and update.
}
BaseModel defines the basic structure for database models.
type Connection ¶
type Connection struct {
BaseModel
UserID string `gorm:"not null" json:"-"`
User *User `gorm:"foreignKey:UserID;references:ID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
TOTPVerify string `json:"-"` // TOTP Verification code, not exposed through API
Password string `json:"-"` // Password for the connection, not exposed through API
Verified bool `gorm:"default:false" json:"verified"`
Sessions []Session `gorm:"foreignKey:ConnectionID;references:ID;constraint:OnDelete:CASCADE" json:"sessions,omitempty"`
}
Connection represents the authentication connections related to a user.
type ConnectionType ¶
type ConnectionType string
ConnectionType represents the type of authentication method.
const ( ProviderEmailType ConnectionType = "email" ProviderGoogleType ConnectionType = "google" ProviderGitHubType ConnectionType = "github" )
Predefined constants for ConnectionType.
func (ConnectionType) WithID ¶
func (c ConnectionType) WithID(id string) string
type Follow ¶
type Follow struct {
BaseModel
UserID string `gorm:"not null" json:"user_id"` // ID of the user who is following
User User `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user,omitempty"` // The user who is following
FollowedID string `gorm:"not null" json:"followed_id"` // ID of the user being followed
Followed User `gorm:"foreignKey:FollowedID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"followed,omitempty"` // The user being followed
}
Follow represents a relationship where a User is following another User.
type Like ¶
type Like struct {
BaseModel
UserID string `gorm:"not null" json:"user_id"` // ID of the user who liked the post
User *User `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user,omitempty"` // The user who liked the post
PostID string `gorm:"not null" json:"post_id"` // ID of the post that was liked
Post *Post `gorm:"foreignKey:PostID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"post,omitempty"` // The post that was liked
}
Like represents a 'like' given by a user to a post.
type Post ¶
type Post struct {
BaseModel
UserID string `gorm:"not null" json:"user_id"` // ID of the user who created the post
User User `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user,omitempty"` // The user who created the post
ParentID *string `gorm:"index" json:"parent_id,omitempty"` // ID of the parent post, if this is a reply or repost
Parent *Post `gorm:"foreignKey:ParentID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"parent,omitempty"` // The parent post
Type PostType `json:"type"` // The type of the post (post, reply, repost)
Content *string `gorm:"type:text" json:"content,omitempty"`
Posts []Post `gorm:"foreignKey:ParentID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"posts,omitempty"` // Posts associated with the post
Likes []Like `gorm:"foreignKey:PostID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"likes,omitempty"` // Likes associated with the post
// Ignored by GORM and populated by the handler.
Liked bool `gorm:"-" json:"liked,omitempty"` // Flag indicating whether the post was liked by the current user
// Counts are ignored by GORM and are populated by the handler.
Counts struct {
Likes int `gorm:"-" json:"likes"` // Number of likes on the post
Replies int `gorm:"-" json:"replies"` // Number of replies to the post
Reposts int `gorm:"-" json:"reposts"` // Number of reposts of the post
} `gorm:"-" json:"counts,omitempty"` // Counts associated with the post
}
Post represents a user's post with potential relationships to other posts.
type Session ¶
type Session struct {
BaseModel
ConnectionID string `gorm:"not null" json:"-"`
Connection *Connection `gorm:"foreignKey:ConnectionID;references:ID;constraint:OnDelete:CASCADE" json:"connection,omitempty"`
Info SessionInfo `gorm:"embedded;embeddedPrefix:info_" json:"info,omitempty"`
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
}
Session represents an authenticated session related to a connection.
type SessionInfo ¶
type SessionInfo struct {
IPAddresses pq.StringArray `gorm:"type:text[]" json:"ip_addresses,omitempty"`
UserAgent string `gorm:"size:255" json:"user_agent,omitempty"`
}
SessionInfo holds information about the session such as IP address and user agent.
type Timestamps ¶
type Timestamps struct {
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` // Time of creation.
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` // Time of update.
}
Timestamps holds creation and update times.
func (*Timestamps) BeforeCreate ¶
func (t *Timestamps) BeforeCreate(tx *gorm.DB) error
BeforeCreate sets timestamps before creating a record.
type User ¶
type User struct {
BaseModel
JoinID int64 `gorm:"not null;unique;autoIncrement" json:"join_id"` // A unique joining ID for the user
Username string `gorm:"size:255;not null;unique" json:"username"` // The user's chosen username, unique across the system
DisplayName string `gorm:"size:255" json:"display_name"` // The user's display name, shown to other users
Avatar string `json:"avatar"` // URL to the user's avatar image
Banner string `json:"banner"` // URL to the user's banner image
Admin bool `gorm:"not null;default:false" json:"admin"` // Flag indicating whether the user has administrative privileges
VerifiedPerson bool `gorm:"not null;default:false" json:"verified_person"` // Flag indicating whether the user is a verified person
Email string `gorm:"size:255;unique;not null" json:"-"` // The user's email address, hidden in JSON responses
MFA string `json:"-"` // Multi-Factor Authentication details, if enabled, not exposed through API
Suspended bool `gorm:"default:false" json:"suspended"` // Flag indicating whether the user's account is suspended
// Relationships
Following []Follow `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"following,omitempty"` // List of users that this user is following
Followers []Follow `gorm:"foreignKey:FollowedID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"followers,omitempty"` // List of users that follow this user
Connections []Connection `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"connections,omitempty"` // Authentication connections associated with the user
Posts []Post `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-"` // Posts created by the user
Likes []Like `gorm:"foreignKey:UserID;references:ID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-"` // Likes made by the user on posts
// Fields Hidden from GORM
YouFollow bool `gorm:"-" json:"you_follow"` // Flag indicating whether the current user follows this user
FollowsYou bool `gorm:"-" json:"follows_you"` // Flag indicating whether this user follows the current user
}
User represents the system user with related authentication details and profile information.