model

package
v0.0.0-...-2403d1f Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2017 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentVersion = "1.0"
View Source
const DefUserID int64 = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	Model
	UserID int64 `gorm:"index"`

	DomainName string   `gorm:"column:domain_name;unique_index"`
	Recodes    []Recode `gorm:"ForeignKey:DomainID"`
	Synced     bool     `gorm:"column:synced;default:'false'"` //for slave
}

func (Domain) TableName

func (Domain) TableName() string

type IDatabase

type IDatabase interface {
	Init() error
	Close() error

	IDomains

	FindByKey(key string) (*Recode, error)

	ClearRecodes(bSynced bool) error

	GetVersion() int64
	SetVersion(v int64) //only slave sync

	BeginTransaction() (IDatabase, error)
	Rollback() error
	Commit() error

	RegListener(l OnDomainChanged)
	UnRegListener(l OnDomainChanged)
}

type IDomains

type IDomains interface {
	NewDomain(userID int64, domain *Domain) (int64, error)
	UpdateDomain(domainID int64, newName string) error
	DeleteDomain(domainID int64) error
	GetDomain(domainID int64) (*Domain, error)
	FindDomainByName(domain string) (*Domain, error)
	GetDomains(userID int64) ([]*Domain, error)
	GetAllDomains(offset, limit int) ([]*Domain, error)

	GetRecodes(domainID int64, offset, limit int) ([]*Recode, error)
	NewRecode(domainID int64, r *Recode) (int64, error)
	GetRecode(id int64) (*Recode, error)
	DeleteRecode(id int64) error
	UpdateRecode(id int64, r *Recode) error
	FindByName(domainID int64, name string) (*Recode, error)
}

type Model

type Model struct {
	ID        int64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type OnDomainChanged

type OnDomainChanged func()

type Recode

type Recode struct {
	Model
	DomainID int64 `gorm:"unique_index:recode_unique;column:domain_id;index"`

	Dynamic   bool           `gorm:"column:dynamic"` //是否未动态
	UpdateKey sql.NullString `gorm:"column:key;unique_index"`
	Synced    bool           `gorm:"column:synced;default:'false'"` //for slave

	RecordType  RecodeType `gorm:"unique_index:recode_unique;column:type;type:int"` // 1 ipv4
	RecordHost  string     `gorm:"unique_index:recode_unique;column:host"`
	RecodeValue string     `gorm:"unique_index:recode_unique;column:value"`
	TTL         uint32     `gorm:"column:ttl"`
}

func (Recode) TableName

func (Recode) TableName() string

type RecodeType

type RecodeType uint16
const (
	NONE_ RecodeType = iota
	A
	AAAA
	CNAME
	LAST_
)

type SchemaVersion

type SchemaVersion struct {
	Model
	Version string `gorm:"column:version"`
}

func (SchemaVersion) TableName

func (SchemaVersion) TableName() string

type User

type User struct {
	Model
	Name    string   `gorm:"size:255"`
	Domains []Domain `gorm:"ForeignKey:UserID"`
}

func (User) TableName

func (User) TableName() string

type Version

type Version struct {
	SchemaVersion string `json:"schema_version"`
	DataVersion   int64  `json:"data_version"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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