aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-18 20:45:22 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-18 20:45:22 +0800
commit18706a6e8377d0e0061b3d29562287d718b70f36 (patch)
tree01a7ff7ff044a6d6e83ad4124479937cd7cba948
parentgofumpt (diff)
downloadforge-18706a6e8377d0e0061b3d29562287d718b70f36.tar.gz
forge-18706a6e8377d0e0061b3d29562287d718b70f36.tar.zst
forge-18706a6e8377d0e0061b3d29562287d718b70f36.zip
Remove underscores from Go code, pt 2
-rw-r--r--acl.go8
-rw-r--r--config.go2
-rw-r--r--database.go10
-rw-r--r--fedauth.go8
-rw-r--r--git_format_patch.go18
-rw-r--r--git_hooks_deploy.go14
-rw-r--r--git_hooks_handle.go20
-rw-r--r--http_global.go4
-rw-r--r--http_handle_group_index.go8
-rw-r--r--http_handle_index.go4
-rw-r--r--http_handle_repo_commit.go2
-rw-r--r--http_server.go2
-rw-r--r--resources.go8
-rw-r--r--ssh_utils.go2
14 files changed, 55 insertions, 55 deletions
diff --git a/acl.go b/acl.go
index d2e8190..8d23dc3 100644
--- a/acl.go
+++ b/acl.go
@@ -9,9 +9,9 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
-// get_path_perm_by_group_repo_key returns the filesystem path and direct
+// getRepoInfo returns the filesystem path and direct
// access permission for a given repo and a provided ssh public key.
-func get_path_perm_by_group_repo_key(ctx context.Context, group_path []string, repo_name, ssh_pubkey string) (repo_id int, filesystem_path string, access bool, contrib_requirements, user_type string, user_id int, err error) {
+func getRepoInfo(ctx context.Context, group_path []string, repoName, sshPubkey string) (repoID int, fsPath string, access bool, contribReq, userType string, userID int, err error) {
err = database.QueryRow(ctx, `
WITH RECURSIVE group_path_cte AS (
-- Start: match the first name in the path where parent_group IS NULL
@@ -51,7 +51,7 @@ LEFT JOIN users u ON u.id = s.user_id
LEFT JOIN user_group_roles ugr ON ugr.group_id = g.id AND ugr.user_id = u.id
WHERE g.depth = cardinality($1::text[])
AND r.name = $2
-`, pgtype.FlatArray[string](group_path), repo_name, ssh_pubkey,
- ).Scan(&repo_id, &filesystem_path, &access, &contrib_requirements, &user_type, &user_id)
+`, pgtype.FlatArray[string](group_path), repoName, sshPubkey,
+ ).Scan(&repoID, &fsPath, &access, &contribReq, &userType, &userID)
return
}
diff --git a/config.go b/config.go
index 2f89ba7..8cd76c9 100644
--- a/config.go
+++ b/config.go
@@ -66,7 +66,7 @@ func loadConfig(path string) (err error) {
return err
}
- global_data["forge_title"] = config.General.Title
+ globalData["forge_title"] = config.General.Title
return nil
}
diff --git a/database.go b/database.go
index 9068736..2406d01 100644
--- a/database.go
+++ b/database.go
@@ -9,9 +9,9 @@ import (
"github.com/jackc/pgx/v5"
)
-// query_name_desc_list is a helper function that executes a query and returns a
+// queryNameDesc is a helper function that executes a query and returns a
// list of name_desc_t results.
-func query_name_desc_list(ctx context.Context, query string, args ...any) (result []name_desc_t, err error) {
+func queryNameDesc(ctx context.Context, query string, args ...any) (result []nameDesc, err error) {
var rows pgx.Rows
if rows, err = database.Query(ctx, query, args...); err != nil {
@@ -24,13 +24,13 @@ func query_name_desc_list(ctx context.Context, query string, args ...any) (resul
if err = rows.Scan(&name, &description); err != nil {
return nil, err
}
- result = append(result, name_desc_t{name, description})
+ result = append(result, nameDesc{name, description})
}
return result, rows.Err()
}
-// name_desc_t holds a name and a description.
-type name_desc_t struct {
+// nameDesc holds a name and a description.
+type nameDesc struct {
Name string
Description string
}
diff --git a/fedauth.go b/fedauth.go
index e1fcfff..6687fe3 100644
--- a/fedauth.go
+++ b/fedauth.go
@@ -15,7 +15,7 @@ import (
"github.com/jackc/pgx/v5"
)
-func check_and_update_federated_user_status(ctx context.Context, user_id int, service, remote_username, pubkey string) (bool, error) {
+func fedauth(ctx context.Context, user_id int, service, remote_username, pubkey string) (bool, error) {
var err error
var resp *http.Response
matched := false
@@ -51,11 +51,11 @@ func check_and_update_federated_user_status(ctx context.Context, user_id int, se
return false, err
}
- line_split := strings.Split(line, " ")
- if len(line_split) < 2 {
+ lineSplit := strings.Split(line, " ")
+ if len(lineSplit) < 2 {
continue
}
- line = strings.Join(line_split[:2], " ")
+ line = strings.Join(lineSplit[:2], " ")
if line == pubkey {
matched = true
diff --git a/git_format_patch.go b/git_format_patch.go
index 2cf66ed..3533eca 100644
--- a/git_format_patch.go
+++ b/git_format_patch.go
@@ -14,12 +14,12 @@ import (
// get_patch_from_commit formats a commit object as if it was returned by
// git-format-patch.
-func format_patch_from_commit(commit *object.Commit) (final string, err error) {
+func fmtCommitPatch(commit *object.Commit) (final string, err error) {
var patch *object.Patch
var buf bytes.Buffer
var author object.Signature
var date string
- var commit_msg_title, commit_msg_details string
+ var commitTitle, commitDetails string
if _, patch, err = get_patch_from_commit(commit); err != nil {
return "", err
@@ -28,20 +28,20 @@ func format_patch_from_commit(commit *object.Commit) (final string, err error) {
author = commit.Author
date = author.When.Format(time.RFC1123Z)
- commit_msg_title, commit_msg_details, _ = strings.Cut(commit.Message, "\n")
+ commitTitle, commitDetails, _ = strings.Cut(commit.Message, "\n")
// This date is hardcoded in Git.
fmt.Fprintf(&buf, "From %s Mon Sep 17 00:00:00 2001\n", commit.Hash)
fmt.Fprintf(&buf, "From: %s <%s>\n", author.Name, author.Email)
fmt.Fprintf(&buf, "Date: %s\n", date)
- fmt.Fprintf(&buf, "Subject: [PATCH] %s\n\n", commit_msg_title)
+ fmt.Fprintf(&buf, "Subject: [PATCH] %s\n\n", commitTitle)
- if commit_msg_details != "" {
- commit_msg_details_first_line, commit_msg_details_rest, _ := strings.Cut(commit_msg_details, "\n")
- if strings.TrimSpace(commit_msg_details_first_line) == "" {
- commit_msg_details = commit_msg_details_rest
+ if commitDetails != "" {
+ commitDetails1, commitDetails2, _ := strings.Cut(commitDetails, "\n")
+ if strings.TrimSpace(commitDetails1) == "" {
+ commitDetails = commitDetails2
}
- buf.WriteString(commit_msg_details)
+ buf.WriteString(commitDetails)
buf.WriteString("\n")
}
buf.WriteString("---\n")
diff --git a/git_hooks_deploy.go b/git_hooks_deploy.go
index d95d6a5..992f892 100644
--- a/git_hooks_deploy.go
+++ b/git_hooks_deploy.go
@@ -15,20 +15,20 @@ import (
// pre-compiled during the build process; see the Makefile.
func deployHooks() (err error) {
err = func() (err error) {
- var src_fd fs.File
- var dst_fd *os.File
+ var srcFD fs.File
+ var dstFD *os.File
- if src_fd, err = resources_fs.Open("hookc/hookc"); err != nil {
+ if srcFD, err = resourcesFS.Open("hookc/hookc"); err != nil {
return err
}
- defer src_fd.Close()
+ defer srcFD.Close()
- if dst_fd, err = os.OpenFile(filepath.Join(config.Hooks.Execs, "hookc"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755); err != nil {
+ if dstFD, err = os.OpenFile(filepath.Join(config.Hooks.Execs, "hookc"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755); err != nil {
return err
}
- defer dst_fd.Close()
+ defer dstFD.Close()
- if _, err = io.Copy(dst_fd, src_fd); err != nil {
+ if _, err = io.Copy(dstFD, srcFD); err != nil {
return err
}
diff --git a/git_hooks_handle.go b/git_hooks_handle.go
index e23b7ce..e02619f 100644
--- a/git_hooks_handle.go
+++ b/git_hooks_handle.go
@@ -24,13 +24,13 @@ import (
)
var (
- err_get_fd = errors.New("unable to get file descriptor")
- err_get_ucred = errors.New("failed getsockopt")
+ errGetFD = errors.New("unable to get file descriptor")
+ errGetUcred = errors.New("failed getsockopt")
)
-// hooks_handle_connection handles a connection from hookc via the
+// hooksHandler handles a connection from hookc via the
// unix socket.
-func hooks_handle_connection(conn net.Conn) {
+func hooksHandler(conn net.Conn) {
var ctx context.Context
var cancel context.CancelFunc
var ucred *syscall.Ucred
@@ -47,7 +47,7 @@ func hooks_handle_connection(conn net.Conn) {
// There aren't reasonable cases where someone would run this as
// another user.
- if ucred, err = get_ucred(conn); err != nil {
+ if ucred, err = getUcred(conn); err != nil {
if _, err = conn.Write([]byte{1}); err != nil {
return
}
@@ -180,7 +180,7 @@ func hooks_handle_connection(conn net.Conn) {
return 1
}
- ok, err := check_and_update_federated_user_status(ctx, pack_to_hook.user_id, service, username, pack_to_hook.pubkey)
+ ok, err := fedauth(ctx, pack_to_hook.user_id, service, username, pack_to_hook.pubkey)
if err != nil {
wf_error(ssh_stderr, "Failed to verify federated user identifier %#v: %v", federated_user_identifier, err)
return 1
@@ -325,21 +325,21 @@ func serveGitHooks(listener net.Listener) error {
if err != nil {
return err
}
- go hooks_handle_connection(conn)
+ go hooksHandler(conn)
}
}
-func get_ucred(conn net.Conn) (ucred *syscall.Ucred, err error) {
+func getUcred(conn net.Conn) (ucred *syscall.Ucred, err error) {
var unix_conn *net.UnixConn = conn.(*net.UnixConn)
var fd *os.File
if fd, err = unix_conn.File(); err != nil {
- return nil, err_get_fd
+ return nil, errGetFD
}
defer fd.Close()
if ucred, err = syscall.GetsockoptUcred(int(fd.Fd()), syscall.SOL_SOCKET, syscall.SO_PEERCRED); err != nil {
- return nil, err_get_ucred
+ return nil, errGetUcred
}
return ucred, nil
}
diff --git a/http_global.go b/http_global.go
index 20a1cbc..0790b3c 100644
--- a/http_global.go
+++ b/http_global.go
@@ -3,8 +3,8 @@
package main
-// global_data is passed as "global" when rendering HTML templates.
-var global_data = map[string]any{
+// globalData is passed as "global" when rendering HTML templates.
+var globalData = map[string]any{
"server_public_key_string": &server_public_key_string,
"server_public_key_fingerprint": &server_public_key_fingerprint,
"forge_version": VERSION,
diff --git a/http_handle_group_index.go b/http_handle_group_index.go
index 911363b..2c27117 100644
--- a/http_handle_group_index.go
+++ b/http_handle_group_index.go
@@ -14,8 +14,8 @@ import (
func handle_group_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
var group_path []string
- var repos []name_desc_t
- var subgroups []name_desc_t
+ var repos []nameDesc
+ var subgroups []nameDesc
var err error
var group_id int
var group_description string
@@ -149,7 +149,7 @@ func handle_group_index(w http.ResponseWriter, r *http.Request, params map[strin
http.Error(w, "Error getting repos: "+err.Error(), http.StatusInternalServerError)
return
}
- repos = append(repos, name_desc_t{name, description})
+ repos = append(repos, nameDesc{name, description})
}
if err = rows.Err(); err != nil {
http.Error(w, "Error getting repos: "+err.Error(), http.StatusInternalServerError)
@@ -174,7 +174,7 @@ func handle_group_index(w http.ResponseWriter, r *http.Request, params map[strin
http.Error(w, "Error getting subgroups: "+err.Error(), http.StatusInternalServerError)
return
}
- subgroups = append(subgroups, name_desc_t{name, description})
+ subgroups = append(subgroups, nameDesc{name, description})
}
if err = rows.Err(); err != nil {
http.Error(w, "Error getting subgroups: "+err.Error(), http.StatusInternalServerError)
diff --git a/http_handle_index.go b/http_handle_index.go
index 144e9ab..40bea7c 100644
--- a/http_handle_index.go
+++ b/http_handle_index.go
@@ -12,9 +12,9 @@ import (
func handle_index(w http.ResponseWriter, r *http.Request, params map[string]any) {
var err error
- var groups []name_desc_t
+ var groups []nameDesc
- groups, err = query_name_desc_list(r.Context(), "SELECT name, COALESCE(description, '') FROM groups WHERE parent_group IS NULL")
+ groups, err = queryNameDesc(r.Context(), "SELECT name, COALESCE(description, '') FROM groups WHERE parent_group IS NULL")
if err != nil {
http.Error(w, "Error querying groups: "+err.Error(), http.StatusInternalServerError)
return
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go
index 8f2204e..f9b7dc5 100644
--- a/http_handle_repo_commit.go
+++ b/http_handle_repo_commit.go
@@ -49,7 +49,7 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin
}
if commit_id_specified_string_without_suffix != commit_id_specified_string {
var formatted_patch string
- if formatted_patch, err = format_patch_from_commit(commit_object); err != nil {
+ if formatted_patch, err = fmtCommitPatch(commit_object); err != nil {
http.Error(w, "Error formatting patch: "+err.Error(), http.StatusInternalServerError)
return
}
diff --git a/http_server.go b/http_server.go
index 9548a65..747f668 100644
--- a/http_server.go
+++ b/http_server.go
@@ -53,7 +53,7 @@ func (router *httpRouter) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
params["url_segments"] = segments
- params["global"] = global_data
+ params["global"] = globalData
var _user_id int // 0 for none
_user_id, params["username"], err = get_user_info_from_request(r)
params["user_id"] = _user_id
diff --git a/resources.go b/resources.go
index 1a2b706..bbb03c0 100644
--- a/resources.go
+++ b/resources.go
@@ -31,7 +31,7 @@ var source_handler = http.StripPrefix(
)
//go:embed templates/* static/* hookc/hookc
-var resources_fs embed.FS
+var resourcesFS embed.FS
var templates *template.Template
@@ -46,12 +46,12 @@ func loadTemplates() (err error) {
"query_escape": query_escape,
})
- err = fs.WalkDir(resources_fs, "templates", func(path string, d fs.DirEntry, err error) error {
+ err = fs.WalkDir(resourcesFS, "templates", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if !d.IsDir() {
- content, err := fs.ReadFile(resources_fs, path)
+ content, err := fs.ReadFile(resourcesFS, path)
if err != nil {
return err
}
@@ -74,7 +74,7 @@ func loadTemplates() (err error) {
var static_handler http.Handler
func init() {
- static_fs, err := fs.Sub(resources_fs, "static")
+ static_fs, err := fs.Sub(resourcesFS, "static")
if err != nil {
panic(err)
}
diff --git a/ssh_utils.go b/ssh_utils.go
index ac0781e..d9c11da 100644
--- a/ssh_utils.go
+++ b/ssh_utils.go
@@ -59,7 +59,7 @@ func get_repo_path_perms_from_ssh_path_pubkey(ctx context.Context, ssh_path, ssh
repo_name = module_name
switch module_type {
case "repos":
- _1, _2, _3, _4, _5, _6, _7 := get_path_perm_by_group_repo_key(ctx, group_path, module_name, ssh_pubkey)
+ _1, _2, _3, _4, _5, _6, _7 := getRepoInfo(ctx, group_path, module_name, ssh_pubkey)
return group_path, repo_name, _1, _2, _3, _4, _5, _6, _7
default:
return []string{}, "", 0, "", false, "", "", 0, err_ssh_illegal_endpoint