github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/install/install.go (about)

     1  package install
     2  
     3  import (
     4  	"fmt"
     5  
     6  	qgen "github.com/Azareal/Gosora/query_gen"
     7  )
     8  
     9  var adapters = make(map[string]InstallAdapter)
    10  
    11  type InstallAdapter interface {
    12  	Name() string
    13  	DefaultPort() string
    14  	SetConfig(dbHost, dbUsername, dbPassword, dbName, dbPort string)
    15  	InitDatabase() error
    16  	TableDefs() error
    17  	InitialData() error
    18  	CreateAdmin() error
    19  
    20  	DBHost() string
    21  	DBUsername() string
    22  	DBPassword() string
    23  	DBName() string
    24  	DBPort() string
    25  }
    26  
    27  func Lookup(name string) (InstallAdapter, bool) {
    28  	adap, ok := adapters[name]
    29  	return adap, ok
    30  }
    31  
    32  func createAdmin() error {
    33  	fmt.Println("Creating the admin user")
    34  	hashedPassword, salt, e := BcryptGeneratePassword("password")
    35  	if e != nil {
    36  		return e
    37  	}
    38  
    39  	// Build the admin user query
    40  	adminUserStmt, e := 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(),'',''")
    41  	if e != nil {
    42  		return e
    43  	}
    44  
    45  	// Run the admin user query
    46  	_, e = adminUserStmt.Exec(hashedPassword, salt)
    47  	return e
    48  }