system

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyPictureDisableGravatar       = "picture.disable_gravatar"
	KeyPictureEnableFederatedAvatar = "picture.enable_federated_avatar"
)

enumerate all system setting keys

Variables

View Source
var (
	GravatarSourceURL *url.URL
	LibravatarService *libravatar.Libravatar
)

Functions

func CountNotices

func CountNotices() int64

CountNotices returns number of notices.

func CreateNotice

func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error

CreateNotice creates new system notice.

func CreateRepositoryNotice

func CreateRepositoryNotice(desc string, args ...interface{}) error

CreateRepositoryNotice creates new system notice with type NoticeRepository.

func DeleteNotice

func DeleteNotice(id int64) error

DeleteNotice deletes a system notice by given ID.

func DeleteNotices

func DeleteNotices(start, end int64) error

DeleteNotices deletes all notices with ID from start to end (inclusive).

func DeleteNoticesByIDs

func DeleteNoticesByIDs(ids []int64) error

DeleteNoticesByIDs deletes notices by given IDs.

func DeleteOldSystemNotices

func DeleteOldSystemNotices(olderThan time.Duration) (err error)

DeleteOldSystemNotices deletes all old system notices from database.

func DeleteSetting

func DeleteSetting(ctx context.Context, setting *Setting) error

DeleteSetting deletes a specific setting for a user

func GetAppStateContent

func GetAppStateContent(key string) (content string, err error)

GetAppStateContent gets an app state from database

func GetSettingBool

func GetSettingBool(ctx context.Context, key string) bool

GetSettingBool return bool value of setting, none existing keys and errors are ignored and result in false

func GetSettingWithCache

func GetSettingWithCache(ctx context.Context, key string) (string, error)

GetSettingWithCache returns the setting value via the key

func GetSettingWithCacheBool

func GetSettingWithCacheBool(ctx context.Context, key string) bool

func GetSettings

func GetSettings(ctx context.Context, keys []string) (map[string]*Setting, error)

GetSettings returns specific settings

func Init

func Init(ctx context.Context) error

func IsErrDataExpired

func IsErrDataExpired(err error) bool

IsErrDataExpired return true if err is ErrDataExpired

func IsErrSettingIsNotExist

func IsErrSettingIsNotExist(err error) bool

IsErrSettingIsNotExist return true if err is ErrSettingIsNotExist

func RemoveAllWithNotice

func RemoveAllWithNotice(ctx context.Context, title, path string)

RemoveAllWithNotice removes all directories in given path and creates a system notice when error occurs.

func RemoveStorageWithNotice

func RemoveStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, title, path string)

RemoveStorageWithNotice removes a file from the storage and creates a system notice when error occurs.

func SaveAppStateContent

func SaveAppStateContent(key, content string) error

SaveAppStateContent saves the app state item to database

func SetSetting

func SetSetting(ctx context.Context, setting *Setting) error

SetSetting updates a users' setting for a specific key

func SetSettingNoVersion

func SetSettingNoVersion(ctx context.Context, key, value string) error

Types

type AllSettings

type AllSettings map[string]*Setting

func GetAllSettings

func GetAllSettings(ctx context.Context) (AllSettings, error)

GetAllSettings returns all settings from user

func (AllSettings) Get

func (settings AllSettings) Get(key string) Setting

func (AllSettings) GetBool

func (settings AllSettings) GetBool(key string) bool

func (AllSettings) GetVersion

func (settings AllSettings) GetVersion(key string) int

type AppState

type AppState struct {
	ID       string `xorm:"pk varchar(200)"`
	Revision int64
	Content  string `xorm:"LONGTEXT"`
}

AppState represents a state record in database if one day we would make Gitea run as a cluster, we can introduce a new field `Scope` here to store different states for different nodes

type ErrDataExpired

type ErrDataExpired struct {
	Key string
}

ErrDataExpired represents an error that update a record which has been updated by another thread

func (ErrDataExpired) Error

func (err ErrDataExpired) Error() string

Error implements error

type ErrSettingIsNotExist

type ErrSettingIsNotExist struct {
	Key string
}

ErrSettingIsNotExist represents an error that a setting is not exist with special key

func (ErrSettingIsNotExist) Error

func (err ErrSettingIsNotExist) Error() string

Error implements error

type Notice

type Notice struct {
	ID          int64 `xorm:"pk autoincr"`
	Type        NoticeType
	Description string             `xorm:"TEXT"`
	CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
}

Notice represents a system notice for admin.

func Notices

func Notices(page, pageSize int) ([]*Notice, error)

Notices returns notices in given page.

func (*Notice) TrStr

func (n *Notice) TrStr() string

TrStr returns a translation format string.

type NoticeType

type NoticeType int

NoticeType describes the notice type

const (
	// NoticeRepository type
	NoticeRepository NoticeType = iota + 1
	// NoticeTask type
	NoticeTask
)

type Setting

type Setting struct {
	ID           int64              `xorm:"pk autoincr"`
	SettingKey   string             `xorm:"varchar(255) unique"` // ensure key is always lowercase
	SettingValue string             `xorm:"text"`
	Version      int                `xorm:"version"` // prevent to override
	Created      timeutil.TimeStamp `xorm:"created"`
	Updated      timeutil.TimeStamp `xorm:"updated"`
}

Setting is a key value store of user settings

func GetSetting

func GetSetting(ctx context.Context, key string) (*Setting, error)

GetSetting returns specific setting without using the cache

func (*Setting) GetValueBool

func (s *Setting) GetValueBool() bool

func (*Setting) TableName

func (s *Setting) TableName() string

TableName sets the table name for the settings struct

Jump to

Keyboard shortcuts

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