Skip to content
This repository was archived by the owner on Dec 9, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions App.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type App interface {
GetPlugin(name string) Pluginer
SetPlugin(name string, plugin Pluginer) error

GetOptions() *AppOptions
SetOptions(options *AppOptions) error

GetRouter() *echo.Echo
SetRouterGroup(name, path string) *echo.Group
GetRouterGroup(name string) *echo.Group
Expand Down Expand Up @@ -84,6 +87,10 @@ type App interface {
type AppOptions struct {
// Gorm configurations / options
GormOptions gorm.Option
BaseURL string
Port string
Protocol string
Domain string
}

type AppStruct struct {
Expand Down Expand Up @@ -126,6 +133,10 @@ func (r *AppStruct) RegisterPlugin(p Pluginer) {
r.Plugins[p.GetName()] = p
}

func (r *AppStruct) GetPlugins() map[string]Pluginer {
return r.Plugins
}

func (r *AppStruct) GetPlugin(name string) Pluginer {
return r.Plugins[name]
}
Expand All @@ -135,8 +146,13 @@ func (r *AppStruct) SetPlugin(name string, plugin Pluginer) error {
return nil
}

func (r *AppStruct) GetPlugins() map[string]Pluginer {
return r.Plugins
func (r *AppStruct) GetOptions() *AppOptions {
return r.Options
}

func (r *AppStruct) SetOptions(options *AppOptions) error {
r.Options = options
return nil
}

func (r *AppStruct) GetRouter() *echo.Echo {
Expand All @@ -145,16 +161,10 @@ func (r *AppStruct) GetRouter() *echo.Echo {

func (app *AppStruct) NewRequestContext(opts *RequestContextOpts) *RequestContext {
cfg := app.GetConfiguration()
port := cfg.GetF("PORT", "8080")
protocol := cfg.GetF("PROTOCOL", "http")
domain := cfg.GetF("DOMAIN", "localhost")

ctx := RequestContext{
App: app,
EchoContext: opts.EchoContext,
Protocol: protocol,
Domain: domain,
AppOrigin: cfg.GetF("APP_ORIGIN", protocol+"://"+domain+":"+port),
// Title: "",
Theme: cfg.GetF("THEME", "site"),
Layout: "layouts/default",
Expand Down Expand Up @@ -537,6 +547,22 @@ func newApp(options *AppOptions) App {
cfg := configuration.NewCfg()
logger.Init()

if options.Port == "" {
options.Port = cfg.GetF("PORT", "8080")
}

if options.Protocol == "" {
options.Protocol = cfg.GetF("PROTOCOL", "http")
}

if options.Domain == "" {
options.Domain = cfg.GetF("DOMAIN", "localhost")
}

if options.BaseURL == "" {
options.BaseURL = "http://localhost:8080"
}

app := AppStruct{
Options: options,
Theme: cfg.GetF("THEME", "site"),
Expand Down
12 changes: 1 addition & 11 deletions RequestContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,9 @@ type RequestContextOpts struct {
func NewRequestContext(opts *RequestContextOpts) *RequestContext {
app := GetApp()
cfg := app.GetConfiguration()
port := cfg.GetF("PORT", "8080")
protocol := cfg.GetF("PROTOCOL", "http")
domain := cfg.GetF("DOMAIN", "localhost")

ctx := RequestContext{
App: app,
EchoContext: opts.EchoContext,
Protocol: protocol,
Domain: domain,
AppOrigin: cfg.GetF("APP_ORIGIN", protocol+"://"+domain+":"+port),
// Title: "",
Theme: app.GetTheme(),
Layout: app.GetLayout(),
Expand Down Expand Up @@ -99,10 +92,7 @@ type RequestContext struct {
EchoContext echo.Context
App App

Protocol string
Domain string
AppOrigin string
Title string
Title string

IsAuthenticated bool
AuthenticatedUser UserInterface
Expand Down