From ed069956471b57d408ecfe2b415eb9dcf08e6c53 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sat, 05 Apr 2025 21:23:00 +0800 Subject: [PATCH] Export symbols from database.go --- database.go | 10 +++++----- http_handle_group_index.go | 8 ++++---- http_handle_index.go | 4 ++-- diff --git a/database.go b/database.go index eafad3326dc15a9e3ab2fb5ae25f78611acf7ebb..a627f2d9a07a1042cbba9fdbcf4250a025ba3335 100644 --- a/database.go +++ b/database.go @@ -15,10 +15,10 @@ // to exceptions if appropriate) so they get a consistent view of the database // at a single point. A failure to do so may cause things as serious as // privilege escalation. -// queryNameDesc 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 nameDesc results. The query must return two string arguments, i.e. a // name and a description. -func (s *Server) queryNameDesc(ctx context.Context, query string, args ...any) (result []nameDesc, err error) { +func (s *Server) QueryNameDesc(ctx context.Context, query string, args ...any) (result []NameDesc, err error) { var rows pgx.Rows if rows, err = s.Database.Query(ctx, query, args...); err != nil { @@ -31,13 +31,13 @@ var name, description string if err = rows.Scan(&name, &description); err != nil { return nil, err } - result = append(result, nameDesc{name, description}) + result = append(result, NameDesc{name, description}) } return result, rows.Err() } -// nameDesc holds a name and a description. -type nameDesc struct { +// NameDesc holds a name and a description. +type NameDesc struct { Name string Description string } diff --git a/http_handle_group_index.go b/http_handle_group_index.go index cc3386064b89c60f7dd22f40eb963fb943d2df68..e0e460d4a6a190ead3148f0c86ed48e257fea4c4 100644 --- a/http_handle_group_index.go +++ b/http_handle_group_index.go @@ -19,8 +19,8 @@ // of its subgroups and repos, as well as a form for group maintainers to // create repos. func (s *Server) httpHandleGroupIndex(writer http.ResponseWriter, request *http.Request, params map[string]any) { var groupPath []string - var repos []nameDesc - var subgroups []nameDesc + var repos []NameDesc + var subgroups []NameDesc var err error var groupID int var groupDesc string @@ -154,7 +154,7 @@ if err = rows.Scan(&name, &description); err != nil { errorPage500(writer, params, "Error getting repos: "+err.Error()) return } - repos = append(repos, nameDesc{name, description}) + repos = append(repos, NameDesc{name, description}) } if err = rows.Err(); err != nil { errorPage500(writer, params, "Error getting repos: "+err.Error()) @@ -179,7 +179,7 @@ if err = rows.Scan(&name, &description); err != nil { errorPage500(writer, params, "Error getting subgroups: "+err.Error()) return } - subgroups = append(subgroups, nameDesc{name, description}) + subgroups = append(subgroups, NameDesc{name, description}) } if err = rows.Err(); err != nil { errorPage500(writer, params, "Error getting subgroups: "+err.Error()) diff --git a/http_handle_index.go b/http_handle_index.go index a519a5a7099e1de29de74181e508261e498b8497..fd89a86332bc3d3ddcfd52fa3f1fb72e1eb223e6 100644 --- a/http_handle_index.go +++ b/http_handle_index.go @@ -14,9 +14,9 @@ // httpHandleIndex provides the main index page which includes a list of groups // and some global information such as SSH keys. func (s *Server) httpHandleIndex(writer http.ResponseWriter, request *http.Request, params map[string]any) { var err error - var groups []nameDesc + var groups []NameDesc - groups, err = s.queryNameDesc(request.Context(), "SELECT name, COALESCE(description, '') FROM groups WHERE parent_group IS NULL") + groups, err = s.QueryNameDesc(request.Context(), "SELECT name, COALESCE(description, '') FROM groups WHERE parent_group IS NULL") if err != nil { errorPage500(writer, params, "Error querying groups: "+err.Error()) return -- 2.48.1