This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
suluvir.go
93 lines (80 loc) · 2.6 KB
/
suluvir.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
// Suluvir streaming server
// Copyright (C) 2018 Jannis Fink
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"github.com/suluvir/server/config"
"github.com/suluvir/server/logging"
"github.com/suluvir/server/schema"
"github.com/suluvir/server/web"
"github.com/urfave/cli"
"go.uber.org/zap"
"os"
// apply routes
_ "github.com/suluvir/server/web/handler"
_ "github.com/suluvir/server/web/handler/api/intnl"
_ "github.com/suluvir/server/web/handler/api/v1"
_ "github.com/suluvir/server/web/handler/appstatic"
// make sure to call auth callbacks
_ "github.com/suluvir/server/auth"
_ "github.com/suluvir/server/auth/oauth"
"github.com/suluvir/server/environment"
)
var baseDirectory string
func actionWrapper(callback func() error) error {
environment.SetBaseDirectory(baseDirectory)
environment.ExecuteStartup()
logging.GetLogger().Info("base directory", zap.String("base dir", environment.GetBaseDirectory()))
return callback()
}
func main() {
defer schema.CloseDatabaseConnection()
app := cli.NewApp()
app.Name = "Suluvir"
app.Usage = "Manage your own music"
app.Version = "0.0.1"
app.Copyright = "Suluvir Copyright (C) 2018 Jannis Fink\n" +
" This program comes with ABSOLUTELY NO WARRANTY; for details type `show w' (TODO).\n" +
" This is free software, and you are welcome to redistribute it\n" +
" under certain conditions; type `show c' (TODO) for details.\n"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "base,b",
Value: "",
Destination: &baseDirectory,
Usage: "Set the base path manually",
},
}
app.Commands = []cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Runs the server",
Action: func(c *cli.Context) error {
return actionWrapper(func() error {
return web.InitializeServer(config.GetConfiguration().Web.Port)
})
},
},
{
Name: "update",
Aliases: []string{"u"},
Usage: "Creates or updates the database schema",
Action: func(c *cli.Context) error {
return actionWrapper(schema.CreateOrUpdate)
},
},
}
app.Run(os.Args)
}