This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
forked from uadmin/uadmin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.go
93 lines (83 loc) · 2.58 KB
/
admin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package uadmin
import (
"fmt"
"github.com/miquella/ask"
"github.com/sergeyglazyrindev/uadmin/colors"
"github.com/sergeyglazyrindev/uadmin/core"
"log"
"os"
"strings"
)
type AdminCommand struct {
}
func (c AdminCommand) Proceed(subaction string, args []string) error {
var action string
var help string
var isCorrectActionPassed bool = false
commandRegistry := &core.CommandRegistry{
Actions: make(map[string]core.ICommand),
}
commandRegistry.AddAction("serve", &ServeAdminServer{})
if len(os.Args) > 2 {
action = os.Args[2]
isCorrectActionPassed = commandRegistry.IsRegisteredCommand(action)
}
if !isCorrectActionPassed {
helpText := commandRegistry.MakeHelpText()
help = fmt.Sprintf(`
Please provide what do you want to do ?
%s
`, helpText)
fmt.Print(help)
return nil
}
commandRegistry.RunAction(subaction, "", args)
return nil
}
func (c AdminCommand) GetHelpText() string {
return "Admin functionality for uadmin project"
}
type AdminStartServerOptions struct {
}
type ServeAdminServer struct {
}
const welcomeMessage = "" +
` ___ __ _` + "\n" +
colors.FGBlueB + ` __ __` + colors.FGNormal + `/ | ____/ /___ ___ (_)___` + "\n" +
colors.FGBlueB + ` / / / /` + colors.FGNormal + ` /| |/ __ / __ '__ \/ / __ \` + "\n" +
colors.FGBlueB + `/ /_/ /` + colors.FGNormal + ` ___ / /_/ / / / / / / / / / /` + "\n" +
colors.FGBlueB + `\__,_/` + colors.FGNormal + `_/ |_\__,_/_/ /_/ /_/_/_/ /_/` + "\n"
func (command ServeAdminServer) Proceed(subaction string, args []string) error {
appInstance.InitializeRouter()
migrateCommand := MigrateCommand{}
err := migrateCommand.Proceed("determine-conflicts", []string{})
if err != nil {
core.Trail(core.CRITICAL, "Found problems with migrations")
err = ask.Print("Warning! Found problems with migrations.\n")
if err != nil {
return err
}
var answer string
for true {
answer, err = ask.HiddenAsk("Do you want to start server ?")
if err != nil {
return err
}
if !core.Contains([]string{"yes", "no"}, strings.ToLower(answer)) {
continue
}
break
}
if answer == "no" {
core.Trail(core.WARNING, "You decided to solve first migration problems, so see you next time!")
return nil
}
}
core.Trail(core.OK, "Server Started: http://%s:%d", core.CurrentConfig.D.Admin.BindIP, core.CurrentConfig.D.Admin.ListenPort)
fmt.Println(welcomeMessage)
log.Println(appInstance.Router.Run(fmt.Sprintf("%s:%d", core.CurrentConfig.D.Admin.BindIP, core.CurrentConfig.D.Admin.ListenPort)))
return nil
}
func (command ServeAdminServer) GetHelpText() string {
return "Serve your admin panel"
}