gosora/install/install.go
Azareal cd66782129 push content type for opensearch
don't insert a last ip on installation
save bytes and allocs in the parser
add attach parser test cases
more benchmarks
2020-03-28 07:01:44 +10:00

49 lines
1.1 KiB
Go

package install
import (
"fmt"
qgen "github.com/Azareal/Gosora/query_gen"
)
var adapters = make(map[string]InstallAdapter)
type InstallAdapter interface {
Name() string
DefaultPort() string
SetConfig(dbHost, dbUsername, dbPassword, dbName, dbPort string)
InitDatabase() error
TableDefs() error
InitialData() error
CreateAdmin() error
DBHost() string
DBUsername() string
DBPassword() string
DBName() string
DBPort() string
}
func Lookup(name string) (InstallAdapter, bool) {
adap, ok := adapters[name]
return adap, ok
}
func createAdmin() error {
fmt.Println("Creating the admin user")
hashedPassword, salt, err := BcryptGeneratePassword("password")
if err != nil {
return err
}
// Build the admin user query
adminUserStmt, err := qgen.Builder.SimpleInsert("users", "name, password, salt, email, group, is_super_admin, active, createdAt, lastActiveAt, lastLiked, oldestItemLikedCreatedAt, message, last_ip", "'Admin',?,?,'admin@localhost',1,1,1,UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),UTC_TIMESTAMP(),'',''")
if err != nil {
return err
}
// Run the admin user query
_, err = adminUserStmt.Exec(hashedPassword, salt)
return err
}