diff --git a/api/account.go b/api/account.go index 37cf9a1..37c4c7f 100644 --- a/api/account.go +++ b/api/account.go @@ -1,8 +1,8 @@ package api import ( - "arimelody-web/account/controller" - "arimelody-web/account/model" + "arimelody-web/controller" + "arimelody-web/model" "arimelody-web/global" "encoding/json" "fmt" diff --git a/account/controller/account.go b/controller/account.go similarity index 80% rename from account/controller/account.go rename to controller/account.go index 267c43b..a34cd27 100644 --- a/account/controller/account.go +++ b/controller/account.go @@ -1,7 +1,8 @@ package controller import ( - "arimelody-web/account/model" + "arimelody-web/model" + "math/rand" "github.com/jmoiron/sqlx" ) @@ -58,3 +59,13 @@ func DeleteAccount(db *sqlx.DB, accountID string) error { _, err := db.Exec("DELETE FROM account WHERE id=$1", accountID) return err } + +var inviteChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + +func GenerateInviteCode(length int) []byte { + code := []byte{} + for i := 0; i < length; i++ { + code = append(code, inviteChars[rand.Intn(len(inviteChars) - 1)]) + } + return code +} diff --git a/main.go b/main.go index ad6db3c..552a83d 100644 --- a/main.go +++ b/main.go @@ -9,11 +9,11 @@ import ( "path/filepath" "time" - "arimelody-web/account/model" "arimelody-web/admin" "arimelody-web/api" "arimelody-web/global" "arimelody-web/view" + "arimelody-web/controller" "arimelody-web/templates" "github.com/jmoiron/sqlx" @@ -47,7 +47,7 @@ func main() { accountsCount := 0 global.DB.Get(&accountsCount, "SELECT count(*) FROM account") if accountsCount == 0 { - code := model.GenerateInviteCode(8) + code := controller.GenerateInviteCode(8) tx, err := global.DB.Begin() if err != nil { diff --git a/account/model/account.go b/model/account.go similarity index 80% rename from account/model/account.go rename to model/account.go index db32451..16b0e3b 100644 --- a/account/model/account.go +++ b/model/account.go @@ -1,7 +1,6 @@ package model import ( - "math/rand" "time" ) @@ -42,13 +41,3 @@ const ( ReadArtists AccountPrivilege = "read_artists" EditArtists AccountPrivilege = "edit_artists" ) - -var inviteChars = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") - -func GenerateInviteCode(length int) []byte { - code := []byte{} - for i := 0; i < length; i++ { - code = append(code, inviteChars[rand.Intn(len(inviteChars) - 1)]) - } - return code -}