Documentation ¶
Index ¶
- Variables
- func Init() (*gorm.DB, error)
- type CensorLog
- type CensorLogsStore
- type CreateCensorLogOptions
- type CreateQuestionOptions
- type CreateUploadImageOptions
- type CreateUserOptions
- type GetQuestionsByAskUserIDOptions
- type GetQuestionsByUserIDOptions
- type GetQuestionsCountOptions
- type HarassmentSettingType
- type NotifyType
- type Question
- type QuestionsStore
- type UpdateQuestionCensorOptions
- type UpdateUserOptions
- type UploadImage
- type UploadImageQuestion
- type UploadImageQuestionType
- type UploadImagesStore
- type User
- type UsersStore
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUserNotExists = errors.New("账号不存在") ErrBadCredential = errors.New("邮箱或密码错误") ErrDuplicateEmail = errors.New("这个邮箱已经注册过账号了!") ErrDuplicateDomain = errors.New("个性域名重复了,换一个吧~") )
View Source
var AllTables = []interface{}{ &User{}, &Question{}, &CensorLog{}, &UploadImage{}, &UploadImageQuestion{}, }
View Source
var ErrCensorLogsNotFound = errors.New("censor logs dose not exist")
View Source
var ErrQuestionNotExist = errors.New("提问不存在")
Functions ¶
Types ¶
type CensorLogsStore ¶
type CensorLogsStore interface { GetByText(ctx context.Context, sourceName, text string, noLongerThan ...time.Time) (*CensorLog, error) Create(ctx context.Context, options CreateCensorLogOptions) error }
var CensorLogs CensorLogsStore
func NewCensorLogsStore ¶
func NewCensorLogsStore(db *gorm.DB) CensorLogsStore
type CreateCensorLogOptions ¶
type CreateCensorLogOptions struct { SourceName string Input string Pass bool RawResponse json.RawMessage }
type CreateQuestionOptions ¶
type CreateUserOptions ¶
type HarassmentSettingType ¶
type HarassmentSettingType string
const ( HarassmentSettingNone HarassmentSettingType = "none" HarassmentSettingTypeRegisterOnly HarassmentSettingType = "register_only" )
type NotifyType ¶
type NotifyType string
const ( NotifyTypeEmail NotifyType = "email" NotifyTypeNone NotifyType = "none" )
type Question ¶
type Question struct { dbutil.Model FromIP string `json:"-"` UserID uint `gorm:"index:idx_question_user_id" json:"-"` Content string `json:"content"` ContentCensorMetadata datatypes.JSON `json:"-"` ContentCensorPass bool `gorm:"->;type:boolean GENERATED ALWAYS AS (IFNULL(content_censor_metadata->'$.pass' = true, false)) STORED NOT NULL" json:"-"` Token string `json:"-"` Answer string `json:"answer"` AnswerCensorMetadata datatypes.JSON `json:"-"` AnswerCensorPass bool `gorm:"->;type:boolean GENERATED ALWAYS AS (IFNULL(answer_censor_metadata->'$.pass' = true, false)) STORED NOT NULL" json:"-"` ReceiveReplyEmail string `json:"-"` AskerUserID uint `json:"-"` IsPrivate bool `gorm:"default: FALSE; NOT NULL" json:"-"` }
type QuestionsStore ¶
type QuestionsStore interface { Create(ctx context.Context, opts CreateQuestionOptions) (*Question, error) GetByID(ctx context.Context, id uint) (*Question, error) GetByUserID(ctx context.Context, userID uint, opts GetQuestionsByUserIDOptions) ([]*Question, error) GetByAskUserID(ctx context.Context, userID uint, opts GetQuestionsByAskUserIDOptions) ([]*Question, error) AnswerByID(ctx context.Context, id uint, answer string) error DeleteByID(ctx context.Context, id uint) error UpdateCensor(ctx context.Context, id uint, opts UpdateQuestionCensorOptions) error Count(ctx context.Context, userID uint, opts GetQuestionsCountOptions) (int64, error) SetPrivate(ctx context.Context, id uint) error SetPublic(ctx context.Context, id uint) error }
var Questions QuestionsStore
func NewQuestionsStore ¶
func NewQuestionsStore(db *gorm.DB) QuestionsStore
type UpdateQuestionCensorOptions ¶
type UpdateQuestionCensorOptions struct { ContentCensorMetadata json.RawMessage AnswerCensorMetadata json.RawMessage }
type UpdateUserOptions ¶
type UpdateUserOptions struct { Name string Avatar string Background string Intro string Notify NotifyType }
type UploadImage ¶
type UploadImageQuestion ¶
type UploadImageQuestion struct { Type UploadImageQuestionType UploadImageID uint QuestionID uint }
type UploadImageQuestionType ¶
type UploadImageQuestionType string
const ( UploadImageQuestionTypeAsk UploadImageQuestionType = "ask" UploadImageQuestionTypeAnswer UploadImageQuestionType = "answer" )
type UploadImagesStore ¶
type UploadImagesStore interface { Create(ctx context.Context, opts CreateUploadImageOptions) (*UploadImage, error) GetByQuestionID(ctx context.Context, questionID uint) ([]*UploadImage, error) GetByTypeQuestionID(ctx context.Context, typ UploadImageQuestionType, questionID uint) ([]*UploadImage, error) }
var UploadImgaes UploadImagesStore
func NewUploadImagesStore ¶
func NewUploadImagesStore(db *gorm.DB) UploadImagesStore
type User ¶
type User struct { gorm.Model `json:"-"` Name string `json:"name"` Password string `json:"-"` Email string `json:"email"` Avatar string `json:"avatar"` Domain string `json:"domain"` Background string `json:"background"` Intro string `json:"intro"` Notify NotifyType `json:"notify"` HarassmentSetting HarassmentSettingType `json:"harassment_setting"` }
func (*User) Authenticate ¶
func (*User) EncodePassword ¶
func (u *User) EncodePassword()
type UsersStore ¶
type UsersStore interface { Create(ctx context.Context, opts CreateUserOptions) error GetByID(ctx context.Context, id uint) (*User, error) GetByEmail(ctx context.Context, email string) (*User, error) GetByDomain(ctx context.Context, domain string) (*User, error) Update(ctx context.Context, id uint, opts UpdateUserOptions) error UpdateHarassmentSetting(ctx context.Context, id uint, typ HarassmentSettingType) error Authenticate(ctx context.Context, email, password string) (*User, error) ChangePassword(ctx context.Context, id uint, oldPassword, newPassword string) error UpdatePassword(ctx context.Context, id uint, newPassword string) error Deactivate(ctx context.Context, id uint) error }
var Users UsersStore
func NewUsersStore ¶
func NewUsersStore(db *gorm.DB) UsersStore
Click to show internal directories.
Click to hide internal directories.