diff options
Diffstat (limited to '')
-rw-r--r-- | http_handle_group_index.go | 6 | ||||
-rw-r--r-- | http_handle_index.go | 6 | ||||
-rw-r--r-- | http_handle_login.go | 16 | ||||
-rw-r--r-- | http_handle_repo_commit.go | 7 | ||||
-rw-r--r-- | http_handle_repo_index.go | 7 | ||||
-rw-r--r-- | http_handle_repo_log.go | 7 | ||||
-rw-r--r-- | http_handle_repo_raw.go | 7 | ||||
-rw-r--r-- | http_handle_repo_tree.go | 13 | ||||
-rw-r--r-- | http_template.go | 10 |
9 files changed, 26 insertions, 53 deletions
diff --git a/http_handle_group_index.go b/http_handle_group_index.go index 670c128..a7d0879 100644 --- a/http_handle_group_index.go +++ b/http_handle_group_index.go @@ -13,9 +13,5 @@ func handle_group_repos(w http.ResponseWriter, r *http.Request, params map[strin } params["repos"] = repos - err = templates.ExecuteTemplate(w, "group_repos", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "group_repos", params) } diff --git a/http_handle_index.go b/http_handle_index.go index ee92c49..6a870c2 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -11,9 +11,5 @@ func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) return } params["groups"] = groups - err = templates.ExecuteTemplate(w, "index", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "index", params) } diff --git a/http_handle_login.go b/http_handle_login.go index 0785ecc..b43e133 100644 --- a/http_handle_login.go +++ b/http_handle_login.go @@ -14,10 +14,7 @@ import ( func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any) { if r.Method != "POST" { - err := templates.ExecuteTemplate(w, "login", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - } + render_template(w, "login", params) return } @@ -30,10 +27,7 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any) if err != nil { if errors.Is(err, pgx.ErrNoRows) { params["login_error"] = "Unknown username" - err := templates.ExecuteTemplate(w, "login", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - } + render_template(w, "login", params) return } http.Error(w, "Error querying user information: "+err.Error(), http.StatusInternalServerError) @@ -48,11 +42,7 @@ func handle_login(w http.ResponseWriter, r *http.Request, params map[string]any) if !match { params["login_error"] = "Invalid password" - err := templates.ExecuteTemplate(w, "login", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "login", params) return } diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go index ee21f16..2732b4e 100644 --- a/http_handle_repo_commit.go +++ b/http_handle_repo_commit.go @@ -79,11 +79,8 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin } params["file_patches"] = usable_file_patches - err = templates.ExecuteTemplate(w, "repo_commit", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_commit", params) + return } type fake_diff_file struct { diff --git a/http_handle_repo_index.go b/http_handle_repo_index.go index ea1854e..890c5c7 100644 --- a/http_handle_repo_index.go +++ b/http_handle_repo_index.go @@ -40,9 +40,6 @@ func handle_repo_index(w http.ResponseWriter, r *http.Request, params map[string params["clone_url"] = generate_ssh_remote_url(group_name, repo_name) - err = templates.ExecuteTemplate(w, "repo_index", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_index", params) + return } diff --git a/http_handle_repo_log.go b/http_handle_repo_log.go index d4422b7..7fec91d 100644 --- a/http_handle_repo_log.go +++ b/http_handle_repo_log.go @@ -28,9 +28,6 @@ func handle_repo_log(w http.ResponseWriter, r *http.Request, params map[string]a } params["commits"] = commits - err = templates.ExecuteTemplate(w, "repo_log", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_log", params) + return } diff --git a/http_handle_repo_raw.go b/http_handle_repo_raw.go index 1d04f6c..69a6a8c 100644 --- a/http_handle_repo_raw.go +++ b/http_handle_repo_raw.go @@ -71,9 +71,6 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request, params map[string]a params["files"] = build_display_git_tree(target) - err = templates.ExecuteTemplate(w, "repo_raw_dir", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_raw_dir", params) + return } diff --git a/http_handle_repo_tree.go b/http_handle_repo_tree.go index f5fbaad..6babd14 100644 --- a/http_handle_repo_tree.go +++ b/http_handle_repo_tree.go @@ -80,11 +80,7 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string] formatted_encapsulated := template.HTML(formatted_unencapsulated.Bytes()) params["file_contents"] = formatted_encapsulated - err = templates.ExecuteTemplate(w, "repo_tree_file", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_tree_file", params) return } } @@ -97,9 +93,6 @@ func handle_repo_tree(w http.ResponseWriter, r *http.Request, params map[string] params["readme_filename"], params["readme"] = render_readme_at_tree(target) params["files"] = build_display_git_tree(target) - err = templates.ExecuteTemplate(w, "repo_tree_dir", params) - if err != nil { - http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) - return - } + render_template(w, "repo_tree_dir", params) + return } diff --git a/http_template.go b/http_template.go new file mode 100644 index 0000000..d135c71 --- /dev/null +++ b/http_template.go @@ -0,0 +1,10 @@ +package main + +import "net/http" + +func render_template(w http.ResponseWriter, template_name string, params map[string]any) { + err := templates.ExecuteTemplate(w, template_name, params) + if err != nil { + http.Error(w, "Error rendering template: "+err.Error(), http.StatusInternalServerError) + } +} |