models

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Post

type Post struct {
	goodm.Model `bson:",inline"`
	Title       string        `bson:"title"    goodm:"required"`
	Body        string        `bson:"body"     goodm:"required"`
	Author      bson.ObjectID `bson:"author"   goodm:"required,index,ref=users"`
	Status      Status        `bson:"status"   goodm:"enum=draft|published|archived,default=draft"`
	Tags        []string      `bson:"tags"     goodm:"index"`
}

Post is an example model for blog posts.

func (*Post) BeforeCreate

func (p *Post) BeforeCreate(ctx context.Context) error

BeforeCreate sets timestamps on new posts.

func (*Post) BeforeSave

func (p *Post) BeforeSave(ctx context.Context) error

BeforeSave updates the UpdatedAt timestamp.

func (*Post) Indexes

func (p *Post) Indexes() []goodm.CompoundIndex

Indexes returns compound indexes for the Post model.

type Role

type Role string

Role represents a user role.

const (
	RoleAdmin Role = "admin"
	RoleUser  Role = "user"
	RoleMod   Role = "mod"
)

type Status

type Status string

Status represents a post publication status.

const (
	StatusDraft     Status = "draft"
	StatusPublished Status = "published"
	StatusArchived  Status = "archived"
)

type User

type User struct {
	goodm.Model `bson:",inline"`
	Email       string        `bson:"email"    goodm:"unique,index,required"`
	Name        string        `bson:"name"     goodm:"required,immutable"`
	Role        Role          `bson:"role"     goodm:"enum=admin|user|mod,default=user"`
	Age         int           `bson:"age"      goodm:"min=13,max=120"`
	Profile     bson.ObjectID `bson:"profile"  goodm:"ref=profiles"`
	Verified    bool          `bson:"verified" goodm:"default=false"`
}

User is an example model demonstrating goodm schema features.

func (*User) BeforeCreate

func (u *User) BeforeCreate(ctx context.Context) error

BeforeCreate sets default timestamps.

func (*User) Indexes

func (u *User) Indexes() []goodm.CompoundIndex

Indexes returns compound indexes for the User model.

Jump to

Keyboard shortcuts

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