refine install.go
This commit is contained in:
parent
31728d53da
commit
77881a994c
4 changed files with 50 additions and 29 deletions
|
@ -1,19 +0,0 @@
|
||||||
# Application environment
|
|
||||||
# production
|
|
||||||
# development
|
|
||||||
APP_ENV = development
|
|
||||||
|
|
||||||
# HTTP listen port of the application
|
|
||||||
HTTP_LISTEN_ADDR = :3000
|
|
||||||
|
|
||||||
# Database configuration
|
|
||||||
DB_DRIVER = sqlite3
|
|
||||||
DB_USER =
|
|
||||||
DB_HOST =
|
|
||||||
DB_PASSWORD =
|
|
||||||
DB_NAME = app_db
|
|
||||||
|
|
||||||
MIGRATION_DIR = app/db/migrations
|
|
||||||
|
|
||||||
# Application secret for sessions (32 bytes long)
|
|
||||||
APP_SECRET =
|
|
|
@ -1,7 +1,6 @@
|
||||||
# Application environment
|
# Application environment
|
||||||
# production
|
# production or development
|
||||||
# development
|
APP_ENV = development
|
||||||
KIT_ENV = development
|
|
||||||
|
|
||||||
# HTTP listen port of the application
|
# HTTP listen port of the application
|
||||||
HTTP_LISTEN_ADDR = :3000
|
HTTP_LISTEN_ADDR = :3000
|
||||||
|
@ -15,5 +14,10 @@ DB_NAME = app_db
|
||||||
|
|
||||||
MIGRATION_DIR = app/db/migrations
|
MIGRATION_DIR = app/db/migrations
|
||||||
|
|
||||||
# Application secret for sessions (32 bytes long)
|
# Application secret used to secure your sessions.
|
||||||
APP_SECRET =
|
# The secret will be auto generated on install.
|
||||||
|
# If you still want to change it make sure its at
|
||||||
|
# least 32 bytes long.
|
||||||
|
# NOTE: You might want to change this secret when using
|
||||||
|
# your app in production.
|
||||||
|
APP_SECRET = {{app_secret}}
|
|
@ -1,4 +1,4 @@
|
||||||
package db
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/uptrace/bun/extra/bundebug"
|
"github.com/uptrace/bun/extra/bundebug"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Query *bun.DB
|
var DB *bun.DB
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config := db.Config{
|
config := db.Config{
|
||||||
|
@ -27,8 +27,8 @@ func init() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
Query = bun.NewDB(db, sqlitedialect.New())
|
DB = bun.NewDB(db, sqlitedialect.New())
|
||||||
if kit.IsDevelopment() {
|
if kit.IsDevelopment() {
|
||||||
Query.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
|
DB.AddQueryHook(bundebug.NewQueryHook(bundebug.WithVerbose(true)))
|
||||||
}
|
}
|
||||||
}
|
}
|
38
install.go
38
install.go
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
|
@ -46,7 +48,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("-- rename bootstrap to", projectName)
|
fmt.Println("-- renaming bootstrap ->", projectName)
|
||||||
if err := os.Rename(path.Join("gothkit", bootstrapFolderName), projectName); err != nil {
|
if err := os.Rename(path.Join("gothkit", bootstrapFolderName), projectName); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -83,5 +85,39 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("-- renaming .env.local -> .env")
|
||||||
|
if err := os.Rename(
|
||||||
|
path.Join(projectName, ".env.local"),
|
||||||
|
path.Join(projectName, ".env"),
|
||||||
|
); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("-- generating secure secret")
|
||||||
|
pathToDotEnv := path.Join(projectName, ".env")
|
||||||
|
fmt.Println("rewriting ->", pathToDotEnv)
|
||||||
|
b, err := os.ReadFile(pathToDotEnv)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
replacedContent := strings.Replace(string(b), "{{app_secret}}", "foobar", -1)
|
||||||
|
fmt.Println(replacedContent)
|
||||||
|
file, err := os.OpenFile(pathToDotEnv, os.O_WRONLY|os.O_TRUNC, 0644)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
_, err = file.WriteString(replacedContent)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
fmt.Printf("-- project (%s) successfully installed!\n", projectName)
|
fmt.Printf("-- project (%s) successfully installed!\n", projectName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateSecret() string {
|
||||||
|
bytes := make([]byte, 32)
|
||||||
|
if _, err := rand.Read(bytes); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(bytes)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue