model

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteApp

func DeleteApp(id uint) error

DeleteApp deletes the app by the user identifier.

func DeleteService

func DeleteService(id uint) error

DeleteService deletes the service by the service id.

func DeleteUser

func DeleteUser(id uint) error

DeleteUser deletes the user by the user identifier.

func DeleteVersion

func DeleteVersion(id uint) error

DeleteVersion deletes the version by the version id.

func GetSelfDB

func GetSelfDB() *gorm.DB

func InitRWDB

func InitRWDB() *gorm.DB

used for cli

Types

type App

type App struct {
	BasicModel
	AppName string `json:"app_name" gorm:"column:app_name;not null;unique;type:varchar(50)"`
	AppDesc string `json:"app_desc" gorm:"column:app_desc;type:varchar(512)"`

	Services []Service `gorm:"foreignkey:AppID"` //App表不会多任何字段,Service表会多app_id
}

func GetAppByID

func GetAppByID(id int64) (*App, error)

func GetAppByName

func GetAppByName(appname string) (*App, error)

func ListApp

func ListApp(offset, limit int) ([]*App, uint64, error)

ListApp List all apps

func (*App) Create

func (app *App) Create() error

Create creates a new App.

func (*App) TableName

func (a *App) TableName() string

func (*App) Update

func (app *App) Update() error

Update updates an App information.

type BasicModel

type BasicModel struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

type Container

type Container struct {
	CtrName  string     `json:"ctr_name"`
	ImageURL string     `json:"image_url"`
	StartCmd []string   `json:"start_cmd"`
	Envs     []Env      `json:"envs"`
	Volumes  []Volume   `json:"volumes"`
	Ports    []PortPair `json:"ports"`
}

type Database

type Database struct {
	RWdb *gorm.DB //读写未分离
}
var DB *Database

func (*Database) Close

func (db *Database) Close()

func (*Database) Init

func (db *Database) Init()

type Env

type Env struct {
	EnvKey string `json:"env_key"`
	EnvVal string `json:"env_val"`
}

type MAEDeployment

type MAEDeployment struct {
	DeployName string            `json:"deploy_name"`
	NameSapce  string            `json:"name_space"`
	Replicas   int               `json:"replicas"`
	Labels     map[string]string `json:"labels"`
	Containers []Container       `json:"containers"`
}

type MAEService

type MAEService struct {
	SvcName  string            `json:"svc_name"`
	Selector map[string]string `json:"selector"`
	SvcType  apiv1.ServiceType `json:"svc_type"` //clusterip,nodeport,loadbalancer
	Labels   map[string]string `json:"labels"`
}

type PortPair

type PortPair struct {
	PortName   string         `json:"port_name"` // this name can be referred by service
	ImagePort  int32          `json:"image_port"`
	TargetPort int32          `json:"target_port"`
	Protocol   apiv1.Protocol `json:"protocol"` // TCP or UDP
}

type ReqVersion

type ReqVersion struct {
	ServiceID   uint          `json:"svc_id"`
	VersionName string        `json:"version_name"`
	VersionDesc string        `json:"version_desc"`
	VersionConf VersionConfig `json:"version_conf"`
}

type Service

type Service struct {
	BasicModel
	AppID          uint      `json:"app_id" gorm:"column:app_id;not null"`
	SvcName        string    `json:"svc_name" gorm:"column:svc_name;not null;unique;type:varchar(50)"`
	SvcDesc        string    `json:"svc_desc" gorm:"column:svc_desc;type:varchar(512)"`
	CurrentVersion string    `json:"current_version" gorm:"column:current_version"`
	Versions       []Version `gorm:"foreignkey:ServiceID"` //service表不会多任何字段,Version表多一个ServiceID
}

func GetServiceByID

func GetServiceByID(id int64) (*Service, error)

func GetServiceByName

func GetServiceByName(svc_name string) (*Service, error)

func ListService

func ListService(offset, limit int) ([]*Service, uint64, error)

ListService List all services

func ListServiceByAppID

func ListServiceByAppID(offset, limit int, app_id uint) ([]*Service, uint64, error)

List all service belongs to an app

func (*Service) Create

func (svc *Service) Create() error

Create creates a new Service.

func (*Service) TableName

func (c *Service) TableName() string

func (*Service) Update

func (svc *Service) Update() error

Update updates a Service information.

type User

type User struct {
	BasicModel
	UserName     string `json:"username" gorm:"column:username;not null;unique"`
	Email        string `json:"email" gorm:"column:email;not null;unique"`
	PasswordHash string `json:"password" gorm:"column:passwordhash;not null"`
	Confirm      bool   `json:"confirm" gorm:"column:confirm;default:false"`
	Role         string `json:"role" gorm:"column:role;default:'user'"`
}

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUser gets an user by the user's email.

func GetUserByID

func GetUserByID(id uint) (*User, error)

GetUser gets an user by the user id

func GetUserByName

func GetUserByName(username string) (*User, error)

GetUser gets an user by the user name.

func ListUser

func ListUser(offset, limit int) ([]*User, uint64, error)

ListUser List all users

func (*User) Compare

func (u *User) Compare(pwd string) (err error)

Compare with the plain text password. Returns true if it's the same as the encrypted one (in the `User` struct).

func (*User) Create

func (u *User) Create() error

Create creates a new user account.

func (*User) Encrypt

func (u *User) Encrypt() (err error)

Encrypt the user password.

func (*User) TableName

func (c *User) TableName() string

func (*User) Update

func (u *User) Update() error

Update updates an user account information.

func (*User) Validate

func (u *User) Validate() error

Validate the fields.

type Version

type Version struct {
	BasicModel
	ServiceID     uint   `json:"svc_id" gorm:"column:svc_id;not null"`
	Active        bool   `json:"active" gorm:"column:active;default:false"`
	VersionName   string `json:"version_name" gorm:"column:version_name;type:varchar(50)"`
	VersionDesc   string `json:"version_desc" gorm:"column:version_desc;type:varchar(512)"`
	VersionConfig string `json:"version_conf" gorm:"column:version_conf;type:varchar(4096)"`
}

func GetVersionByID

func GetVersionByID(id int64) (*Version, error)

func GetVersionByName

func GetVersionByName(version_name string) (*Version, error)

func ListVersion

func ListVersion(offset, limit int) ([]*Version, uint64, error)

ListVersion List all versions

func ListVersionByServiceID

func ListVersionByServiceID(offset, limit int, service_id uint) ([]*Version, uint64, error)

List all versions belongs to a service

func (*Version) Create

func (v *Version) Create() error

Create creates a new Version.

func (*Version) TableName

func (c *Version) TableName() string

func (*Version) Update

func (v *Version) Update() error

Update updates a Version information.

type VersionConfig

type VersionConfig struct {
	Deployment MAEDeployment `json:"deployment"`
	Svc        MAEService    `json:"svc"` //此处的Svc指的是k8s中的Service的概念
}

type Volume

type Volume struct {
	VolumeName string `json:"volume_name"`
	ReadOnly   bool   `json:"read_only"`
	HostPath   string `json:"host_path"`

	//https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
	HostPathType apiv1.HostPathType `json:"host_path_type"`

	TargetPath string `json:"target_path"`
}

Jump to

Keyboard shortcuts

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