|
| 1 | +// Copyright © 2014-2018 Thomas Rabaix <[email protected]>. |
| 2 | +// |
| 3 | +// Use of this source code is governed by an MIT-style |
| 4 | +// license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +package main |
| 7 | + |
| 8 | +import ( |
| 9 | + "os" |
| 10 | + |
| 11 | + log "github.com/Sirupsen/logrus" |
| 12 | + "github.com/mitchellh/cli" |
| 13 | + "github.com/rande/goapp" |
| 14 | + "github.com/rande/gonode/app/assets" |
| 15 | + "github.com/rande/gonode/core/bindata" |
| 16 | + "github.com/rande/gonode/core/commands" |
| 17 | + "github.com/rande/gonode/core/config" |
| 18 | + "github.com/rande/gonode/core/logger" |
| 19 | + "github.com/rande/gonode/core/router" |
| 20 | + "github.com/rande/gonode/core/security" |
| 21 | + "github.com/rande/gonode/modules/api" |
| 22 | + "github.com/rande/gonode/modules/base" |
| 23 | + "github.com/rande/gonode/modules/blog" |
| 24 | + "github.com/rande/gonode/modules/debug" |
| 25 | + "github.com/rande/gonode/modules/feed" |
| 26 | + node_guard "github.com/rande/gonode/modules/guard" |
| 27 | + "github.com/rande/gonode/modules/media" |
| 28 | + "github.com/rande/gonode/modules/prism" |
| 29 | + "github.com/rande/gonode/modules/raw" |
| 30 | + "github.com/rande/gonode/modules/search" |
| 31 | + "github.com/rande/gonode/modules/setup" |
| 32 | + "github.com/rande/gonode/modules/user" |
| 33 | +) |
| 34 | + |
| 35 | +func Configure(configFile string) *goapp.Lifecycle { |
| 36 | + l := goapp.NewLifecycle() |
| 37 | + |
| 38 | + conf := config.NewConfig() |
| 39 | + config.LoadConfigurationFromFile(configFile, conf) |
| 40 | + |
| 41 | + l.Config(func(app *goapp.App) error { |
| 42 | + assets.UpdateRootDir(conf.BinData.BasePath) |
| 43 | + |
| 44 | + app.Set("gonode.asset", func(app *goapp.App) interface{} { |
| 45 | + return assets.Asset |
| 46 | + }) |
| 47 | + |
| 48 | + return nil |
| 49 | + }) |
| 50 | + |
| 51 | + base.Configure(l, conf) |
| 52 | + debug.Configure(l, conf) |
| 53 | + user.Configure(l, conf) |
| 54 | + raw.Configure(l, conf) |
| 55 | + blog.Configure(l, conf) |
| 56 | + media.Configure(l, conf) |
| 57 | + search.Configure(l, conf) |
| 58 | + feed.Configure(l, conf) |
| 59 | + |
| 60 | + logger.Configure(l, conf) |
| 61 | + commands.Configure(l, conf) |
| 62 | + security.ConfigureCors(l, conf) |
| 63 | + node_guard.Configure(l, conf) |
| 64 | + security.ConfigureSecurity(l, conf) |
| 65 | + api.Configure(l, conf) |
| 66 | + setup.Configure(l, conf) |
| 67 | + bindata.Configure(l, conf) |
| 68 | + prism.Configure(l, conf) |
| 69 | + router.Configure(l, conf) |
| 70 | + |
| 71 | + return l |
| 72 | +} |
| 73 | + |
| 74 | +func main() { |
| 75 | + ui := &cli.BasicUi{Writer: os.Stdout} |
| 76 | + |
| 77 | + c := cli.NewCLI("gonode", "0.0.2-DEV") |
| 78 | + c.Args = os.Args[1:] |
| 79 | + |
| 80 | + c.Commands = map[string]cli.CommandFactory{ |
| 81 | + "server": func() (cli.Command, error) { |
| 82 | + return &commands.ServerCommand{ |
| 83 | + Ui: ui, |
| 84 | + Configure: Configure, |
| 85 | + }, nil |
| 86 | + }, |
| 87 | + } |
| 88 | + |
| 89 | + exitStatus, err := c.Run() |
| 90 | + |
| 91 | + if err != nil { |
| 92 | + log.Println(err) |
| 93 | + } |
| 94 | + |
| 95 | + os.Exit(exitStatus) |
| 96 | +} |
0 commit comments