package app import ( "flag" "fmt" "path/filepath" "git.vinchent.xyz/vinchent/go-web/framework" "git.vinchent.xyz/vinchent/go-web/framework/utils" ) type GoWebApp struct { container framework.Container baseFolder string } const AppVersion = "0.0.1" func ErrParamsAmount(want int, got int) error { return fmt.Errorf("want %d arguments, got %d", want, got) } // NewGoWebApp creates a new GoWeb app. // // \params[in]: container // \params[in]: baseFolder func NewGoWebApp(params ...interface{}) (interface{}, error) { if len(params) != 2 { return nil, ErrParamsAmount(2, len(params)) } container := params[0].(framework.Container) baseFolder := params[1].(string) return &GoWebApp{ container: container, baseFolder: baseFolder, }, nil } func (goweb *GoWebApp) Version() string { return AppVersion } func (goweb *GoWebApp) BaseFolder() string { if goweb.baseFolder != "" { return goweb.baseFolder } // not defined yet var baseFolder string flag.StringVar( &baseFolder, "base_folder", utils.GetExecDirectory(), "base_folder of the app. Use the current path as default value", ) return baseFolder } func (goweb *GoWebApp) ConfigFolder() string { return filepath.Join(goweb.BaseFolder(), "config") } func (goweb *GoWebApp) StorageFolder() string { return filepath.Join(goweb.BaseFolder(), "storage") } func (goweb *GoWebApp) LogFolder() string { // storage/log return filepath.Join(goweb.StorageFolder(), "log") } func (goweb *GoWebApp) ProvidersFolder() string { return filepath.Join(goweb.BaseFolder(), "providers") } func (goweb *GoWebApp) WebFolder() string { return filepath.Join(goweb.BaseFolder(), "web") } func (goweb *GoWebApp) MiddlewaresFolder() string { // http/middlewares return filepath.Join(goweb.WebFolder(), "middlewares") } func (goweb *GoWebApp) ConsoleFolder() string { return filepath.Join(goweb.BaseFolder(), "console") } func (goweb *GoWebApp) CommandsFolder() string { // console/commands return filepath.Join(goweb.ConsoleFolder(), "commands") } func (goweb *GoWebApp) RuntimeFolder() string { return filepath.Join(goweb.StorageFolder(), "runtime") } func (goweb *GoWebApp) TestsFolder() string { return filepath.Join(goweb.BaseFolder(), "tests") }