account index

This commit is contained in:
微凉
2021-11-03 10:37:33 +08:00
parent 04e89754f7
commit d78b64ee3c
5 changed files with 37 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import (
type Account struct {
Name string `json:"name" gorm:"primaryKey" validate:"required"`
Index int `json:"index" validate:"required"`
Type string `json:"type"`
Username string `json:"username"`
Password string `json:"password"`
@ -71,9 +72,13 @@ func GetAccount(name string) (Account, bool) {
return account, ok
}
func GetAccountFiles() []*File {
func GetAccountFiles() ([]*File, error) {
files := make([]*File, 0)
for _, v := range accountsMap {
var accounts []Account
if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil {
return nil, err
}
for _, v := range accounts {
files = append(files, &File{
Name: v.Name,
Size: 0,
@ -81,13 +86,13 @@ func GetAccountFiles() []*File {
UpdatedAt: v.UpdatedAt,
})
}
return files
return files, nil
}
func GetAccounts() []Account {
accounts := make([]Account, 0)
for _, v := range accountsMap {
accounts = append(accounts, v)
func GetAccounts() ([]Account, error) {
var accounts []Account
if err := conf.DB.Order("`index`").Find(&accounts).Error; err != nil {
return nil, err
}
return accounts
return accounts, nil
}