detached 2cec0ac

WIP

commit
2cec0acfc27d9d0d2d0e99d9687429917a26c70f
author
bnema · · 2023-09-17 18:31 UTC
parent
a5fe447
signature
unsigned
6 files · +60 -19
M cmd/main.go +2 -2
@@ -48,8 +48,8 @@ func main() {
4848 e.HidePort = true
4949 e = httpserve.RegisterRoutes(e, a)
5050
51- log.Println("Starting server on port", a.HttpPort)
52- if err := e.Start(fmt.Sprintf(":%d", a.HttpPort)); err != nil {
51+ log.Println("Starting server on port", a.Config.HttpPort)
52+ if err := e.Start(fmt.Sprintf(":%d", a.Config.HttpPort)); err != nil {
5353 log.Fatal("Server error:", err)
5454 }
5555 }
@@ -48,8 +48,8 @@ func main() {
48 e.HidePort = true48 e.HidePort = true
49 e = httpserve.RegisterRoutes(e, a)49 e = httpserve.RegisterRoutes(e, a)
50 50
51- log.Println("Starting server on port", a.HttpPort)51+ log.Println("Starting server on port", a.Config.HttpPort)
52- if err := e.Start(fmt.Sprintf(":%d", a.HttpPort)); err != nil {52+ if err := e.Start(fmt.Sprintf(":%d", a.Config.HttpPort)); err != nil {
53 log.Fatal("Server error:", err)53 log.Fatal("Server error:", err)
54 }54 }
55 }55 }
M internal/app/app.go +53 -13
@@ -4,8 +4,11 @@ import (
44 "database/sql"
55 "fmt"
66 "io/fs"
7+ "log"
78 "os"
89
10+ "github.com/bnema/gordon/internal/gotemplate"
11+ "github.com/bnema/gordon/internal/webui"
912 "github.com/bnema/gordon/pkg/utils/docker"
1013 "github.com/bnema/gordon/pkg/utils/parser"
1114 )
@@ -32,19 +35,30 @@ type App struct {
3235 DB *sql.DB
3336 Config AppConfig
3437 }
35-
3638 type AppConfig struct {
37- RunEnv string `yaml:"runEnv"`
38- BuildVersion string `yaml:"buildVersion"`
39- HttpPort int `yaml:"httpPort"`
40- TopDomain string `yaml:"topDomain"`
41- SubDomain string `yaml:"subDomain"`
42- AdminPath string `yaml:"adminPath"`
43- DockerSock string `yaml:"dockerSock"`
44- PodmanEnable bool `yaml:"podmanEnable"`
45- PodmanSock string `yaml:"podmanSock"`
46- OauthCallbackURL string `yaml:"oauthCallbackURL"`
47- BuildDir string `yaml:"buildDir"`
39+ General GeneralConfig `yaml:"general"`
40+ Http HttpConfig `yaml:"http"`
41+ Admin AdminConfig `yaml:"admin"`
42+ Docker DockerConfig `yaml:"docker"`
43+}
44+
45+type GeneralConfig struct {
46+ RunEnv string `yaml:"runEnv"`
47+ BuildVersion string `yaml:"buildVersion"`
48+}
49+
50+type HttpConfig struct {
51+ Port int `yaml:"port"`
52+ TopDomain string `yaml:"topDomain"`
53+ SubDomain string `yaml:"subDomain"`
54+}
55+
56+type AdminConfig struct {
57+ Path string `yaml:"path"`
58+}
59+
60+type DockerConfig struct {
61+ Sock string `yaml:"sock"`
4862 }
4963
5064 func InitializeEnvironment() {
@@ -53,6 +67,7 @@ func InitializeEnvironment() {
5367 fmt.Errorf("Error initializing environment: %s", err)
5468 }
5569 OauthCallbackURL = GenerateOauthCallbackURL(config)
70+
5671 }
5772
5873 func LoadConfig() (AppConfig, error) {
@@ -62,6 +77,28 @@ func LoadConfig() (AppConfig, error) {
6277 return config, err
6378 }
6479
80+func NewApp() *App {
81+ // Initialize AppConfig
82+ config, err := LoadConfig()
83+ if err != nil {
84+ log.Fatalf("Failed to load configuration: %v", err)
85+ }
86+
87+ // Initialize App
88+ a := &App{
89+ TemplateFS: gotemplate.TemplateFS,
90+ PublicFS: webui.PublicFS,
91+ DBDir: DBDir,
92+ DBFilename: DBFilename,
93+ Config: config,
94+ }
95+
96+ // If you have any other initializations like generating OAuth URL, do them here
97+ OauthCallbackURL = GenerateOauthCallbackURL(config)
98+
99+ return a
100+}
101+
65102 // NewDockerConfig creates and returns a new Docker client configuration based on AppConfig.
66103 func (config *AppConfig) NewDockerConfig() *docker.Config {
67104 return &docker.Config{
@@ -91,8 +128,11 @@ func GenerateOauthCallbackURL(config AppConfig) string {
91128 }
92129
93130 func getEnvPaths() (string, string) {
131+ wd, _ := os.Getwd()
132+ fmt.Println("Current Working Directory:", wd)
133+
94134 if appEnv == "dev" {
95- return "tmp/", "config.yml"
135+ return "/tmp/", "config.yml"
96136 }
97137 return "./", "config.yml"
98138 }
@@ -4,8 +4,11 @@ import (
4 "database/sql"4 "database/sql"
5 "fmt"5 "fmt"
6 "io/fs"6 "io/fs"
7+ "log"
7 "os"8 "os"
8 9
10+ "github.com/bnema/gordon/internal/gotemplate"
11+ "github.com/bnema/gordon/internal/webui"
9 "github.com/bnema/gordon/pkg/utils/docker"12 "github.com/bnema/gordon/pkg/utils/docker"
10 "github.com/bnema/gordon/pkg/utils/parser"13 "github.com/bnema/gordon/pkg/utils/parser"
11 )14 )
@@ -32,19 +35,30 @@ type App struct {
32 DB *sql.DB35 DB *sql.DB
33 Config AppConfig36 Config AppConfig
34 }37 }
35-
36 type AppConfig struct {38 type AppConfig struct {
37- RunEnv string `yaml:"runEnv"`39+ General GeneralConfig `yaml:"general"`
38- BuildVersion string `yaml:"buildVersion"`40+ Http HttpConfig `yaml:"http"`
39- HttpPort int `yaml:"httpPort"`41+ Admin AdminConfig `yaml:"admin"`
40- TopDomain string `yaml:"topDomain"`42+ Docker DockerConfig `yaml:"docker"`
41- SubDomain string `yaml:"subDomain"`43+}
42- AdminPath string `yaml:"adminPath"`44+
43- DockerSock string `yaml:"dockerSock"`45+type GeneralConfig struct {
44- PodmanEnable bool `yaml:"podmanEnable"`46+ RunEnv string `yaml:"runEnv"`
45- PodmanSock string `yaml:"podmanSock"`47+ BuildVersion string `yaml:"buildVersion"`
46- OauthCallbackURL string `yaml:"oauthCallbackURL"`48+}
47- BuildDir string `yaml:"buildDir"`49+
50+type HttpConfig struct {
51+ Port int `yaml:"port"`
52+ TopDomain string `yaml:"topDomain"`
53+ SubDomain string `yaml:"subDomain"`
54+}
55+
56+type AdminConfig struct {
57+ Path string `yaml:"path"`
58+}
59+
60+type DockerConfig struct {
61+ Sock string `yaml:"sock"`
48 }62 }
49 63
50 func InitializeEnvironment() {64 func InitializeEnvironment() {
@@ -53,6 +67,7 @@ func InitializeEnvironment() {
53 fmt.Errorf("Error initializing environment: %s", err)67 fmt.Errorf("Error initializing environment: %s", err)
54 }68 }
55 OauthCallbackURL = GenerateOauthCallbackURL(config)69 OauthCallbackURL = GenerateOauthCallbackURL(config)
70+
56 }71 }
57 72
58 func LoadConfig() (AppConfig, error) {73 func LoadConfig() (AppConfig, error) {
@@ -62,6 +77,28 @@ func LoadConfig() (AppConfig, error) {
62 return config, err77 return config, err
63 }78 }
64 79
80+func NewApp() *App {
81+ // Initialize AppConfig
82+ config, err := LoadConfig()
83+ if err != nil {
84+ log.Fatalf("Failed to load configuration: %v", err)
85+ }
86+
87+ // Initialize App
88+ a := &App{
89+ TemplateFS: gotemplate.TemplateFS,
90+ PublicFS: webui.PublicFS,
91+ DBDir: DBDir,
92+ DBFilename: DBFilename,
93+ Config: config,
94+ }
95+
96+ // If you have any other initializations like generating OAuth URL, do them here
97+ OauthCallbackURL = GenerateOauthCallbackURL(config)
98+
99+ return a
100+}
101+
65 // NewDockerConfig creates and returns a new Docker client configuration based on AppConfig.102 // NewDockerConfig creates and returns a new Docker client configuration based on AppConfig.
66 func (config *AppConfig) NewDockerConfig() *docker.Config {103 func (config *AppConfig) NewDockerConfig() *docker.Config {
67 return &docker.Config{104 return &docker.Config{
@@ -91,8 +128,11 @@ func GenerateOauthCallbackURL(config AppConfig) string {
91 }128 }
92 129
93 func getEnvPaths() (string, string) {130 func getEnvPaths() (string, string) {
131+ wd, _ := os.Getwd()
132+ fmt.Println("Current Working Directory:", wd)
133+
94 if appEnv == "dev" {134 if appEnv == "dev" {
95- return "tmp/", "config.yml"135+ return "/tmp/", "config.yml"
96 }136 }
97 return "./", "config.yml"137 return "./", "config.yml"
98 }138 }
M internal/gotemplate/render/html.go +2 -2
@@ -17,7 +17,7 @@ type Renderer struct {
1717 }
1818
1919 // Render function renders the template with the given data
20-func (r *Renderer) Render(data interface{}, a *app.AppConfig) (string, error) {
20+func (r *Renderer) Render(data interface{}, a *app.App) (string, error) {
2121 if r.ParseError != nil {
2222 return "", fmt.Errorf("failed to parse template: %w", r.ParseError)
2323
@@ -58,6 +58,6 @@ func GetHTMLRenderer(pathStr string, filename string, fs fs.FS, a *app.App) (*Re
5858 }
5959 return &Renderer{
6060 Template: tmpl,
61- BuildVersion: a.BuildVersion,
61+ BuildVersion: a.Config.BuildVersion,
6262 }, nil
6363 }
@@ -17,7 +17,7 @@ type Renderer struct {
17 }17 }
18 18
19 // Render function renders the template with the given data19 // Render function renders the template with the given data
20-func (r *Renderer) Render(data interface{}, a *app.AppConfig) (string, error) {20+func (r *Renderer) Render(data interface{}, a *app.App) (string, error) {
21 if r.ParseError != nil {21 if r.ParseError != nil {
22 return "", fmt.Errorf("failed to parse template: %w", r.ParseError)22 return "", fmt.Errorf("failed to parse template: %w", r.ParseError)
23 23
@@ -58,6 +58,6 @@ func GetHTMLRenderer(pathStr string, filename string, fs fs.FS, a *app.App) (*Re
58 }58 }
59 return &Renderer{59 return &Renderer{
60 Template: tmpl,60 Template: tmpl,
61- BuildVersion: a.BuildVersion,61+ BuildVersion: a.Config.BuildVersion,
62 }, nil62 }, nil
63 }63 }
M internal/httpserve/handler/oauth.go +1 -1
@@ -48,7 +48,7 @@ func RenderLoginPage(c echo.Context, a *app.App) error {
4848
4949 func StartOAuthGithub(c echo.Context, a *app.App) error {
5050 clientID := os.Getenv("GITHUB_APP_ID")
51- redirectDomain := a.OauthCallbackURL
51+ redirectDomain := a.Config.OauthCallbackURL
5252 encodedState := base64.StdEncoding.EncodeToString([]byte("redirectDomain:" + redirectDomain))
5353 fmt.Print("redirectDomain:", redirectDomain)
5454 fmt.Print("encoded state :", encodedState)
@@ -48,7 +48,7 @@ func RenderLoginPage(c echo.Context, a *app.App) error {
48 48
49 func StartOAuthGithub(c echo.Context, a *app.App) error {49 func StartOAuthGithub(c echo.Context, a *app.App) error {
50 clientID := os.Getenv("GITHUB_APP_ID")50 clientID := os.Getenv("GITHUB_APP_ID")
51- redirectDomain := a.OauthCallbackURL51+ redirectDomain := a.Config.OauthCallbackURL
52 encodedState := base64.StdEncoding.EncodeToString([]byte("redirectDomain:" + redirectDomain))52 encodedState := base64.StdEncoding.EncodeToString([]byte("redirectDomain:" + redirectDomain))
53 fmt.Print("redirectDomain:", redirectDomain)53 fmt.Print("redirectDomain:", redirectDomain)
54 fmt.Print("encoded state :", encodedState)54 fmt.Print("encoded state :", encodedState)
M internal/httpserve/router.go +1 -1
@@ -14,7 +14,7 @@ import (
1414
1515 // RegisterRoutes registers all routes for the application
1616 func RegisterRoutes(e *echo.Echo, a *app.App) *echo.Echo {
17- AdminPath := a.AdminPath
17+ AdminPath := a.Config.AdminPath
1818 e.Use(middleware.SetCommonDataMiddleware(a))
1919 e.Use(middleware.ErrorHandler)
2020 // Add session middleware
@@ -14,7 +14,7 @@ import (
14 14
15 // RegisterRoutes registers all routes for the application15 // RegisterRoutes registers all routes for the application
16 func RegisterRoutes(e *echo.Echo, a *app.App) *echo.Echo {16 func RegisterRoutes(e *echo.Echo, a *app.App) *echo.Echo {
17- AdminPath := a.AdminPath17+ AdminPath := a.Config.AdminPath
18 e.Use(middleware.SetCommonDataMiddleware(a))18 e.Use(middleware.SetCommonDataMiddleware(a))
19 e.Use(middleware.ErrorHandler)19 e.Use(middleware.ErrorHandler)
20 // Add session middleware20 // Add session middleware
M pkg/utils/parser/yaml.go +1 -0
@@ -36,6 +36,7 @@ import (
3636 func OpenYamlFile(fs fs.FS, filename string, out interface{}, dir ...string) error {
3737 // Construct the full path of the YAML file
3838 fullPath := filename
39+ fmt.Println("Trying to open file at:", fullPath)
3940 if len(dir) > 0 {
4041 fullPath = filepath.Join(dir[0], filename)
4142 }
@@ -36,6 +36,7 @@ import (
36 func OpenYamlFile(fs fs.FS, filename string, out interface{}, dir ...string) error {36 func OpenYamlFile(fs fs.FS, filename string, out interface{}, dir ...string) error {
37 // Construct the full path of the YAML file37 // Construct the full path of the YAML file
38 fullPath := filename38 fullPath := filename
39+ fmt.Println("Trying to open file at:", fullPath)
39 if len(dir) > 0 {40 if len(dir) > 0 {
40 fullPath = filepath.Join(dir[0], filename)41 fullPath = filepath.Join(dir[0], filename)
41 }42 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close