added some install files
This commit is contained in:
@ -1,23 +1,47 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
|
||||
"code.icod.de/postfix/manager/ent"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var (
|
||||
db string
|
||||
setupPostfix bool
|
||||
setupDovecot bool
|
||||
)
|
||||
|
||||
// installCmd represents the install command
|
||||
var installCmd = &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "installs the database config files for postfix",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("install called")
|
||||
Short: "installs the database config files for postfix and creates the database",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// create database schema
|
||||
client, e := ent.Open("mysql", "dev:dev@tcp(localhost:3306)/postfix")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer client.Close()
|
||||
ctx := context.Background()
|
||||
if e := client.Schema.Create(ctx); e != nil {
|
||||
return e
|
||||
}
|
||||
return nil
|
||||
|
||||
// setup postfix
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(installCmd)
|
||||
|
||||
installCmd.Flags().BoolVar(&setupPostfix, "setup:postfix", true, "--setup:postfix=true|false")
|
||||
installCmd.Flags().BoolVar(&setupPostfix, "setup:dovecot", true, "--setup:dovecot=true|false")
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
|
23
cmd/ui.go
23
cmd/ui.go
@ -7,7 +7,9 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"code.icod.de/postfix/manager/ent"
|
||||
"code.icod.de/postfix/manager/ui"
|
||||
"code.icod.de/postfix/manager/ui/handler"
|
||||
"git.icod.de/dalu/ginpongo2/v5"
|
||||
"github.com/flosch/pongo2/v5"
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -54,21 +56,18 @@ var uiCmd = &cobra.Command{
|
||||
r.HTMLRender = hr
|
||||
}
|
||||
|
||||
// Database
|
||||
client, e := ent.Open("mysql", "dev:dev@tcp(localhost:3306)/postfix")
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
defer client.Close()
|
||||
handler.SetClient(client)
|
||||
|
||||
// Static
|
||||
r.Static("/assets/", "./assets/")
|
||||
|
||||
r.GET("/", func(cx *gin.Context) {
|
||||
ctx := make(pongo2.Context)
|
||||
type Data struct {
|
||||
Target string
|
||||
Message string
|
||||
}
|
||||
ctx["data"] = &Data{
|
||||
Target: "World",
|
||||
Message: "It's a great day to be alive",
|
||||
}
|
||||
cx.HTML(200, "index", ctx)
|
||||
})
|
||||
r.GET("/", handler.GETIndex)
|
||||
|
||||
// serve
|
||||
if strings.HasPrefix(uiAddr, prefixTCP) {
|
||||
|
Reference in New Issue
Block a user