Detailed changes
@@ -17,7 +17,7 @@ import (
var bmStrict = bluemonday.StrictPolicy()
-// createUser is a CLI that creates a new user with the specified username
+// createUser is a CLI that creates a new user with the specified username.
func createUser(dbConn *sql.DB, username string) {
fmt.Println("Creating user", username)
@@ -60,7 +60,7 @@ func createUser(dbConn *sql.DB, username string) {
os.Exit(0)
}
-// deleteUser is a CLI that deletes a user with the specified username
+// deleteUser is a CLI that deletes a user with the specified username.
func deleteUser(dbConn *sql.DB, username string) {
fmt.Println("Deleting user", username)
err := users.Delete(dbConn, username)
@@ -73,7 +73,7 @@ func deleteUser(dbConn *sql.DB, username string) {
os.Exit(0)
}
-// listUsers is a CLI that lists all users in the database
+// listUsers is a CLI that lists all users in the database.
func listUsers(dbConn *sql.DB) {
fmt.Println("Listing all users")
@@ -18,13 +18,13 @@ var schema string
var mutex = &sync.Mutex{}
-// Open opens a connection to the SQLite database
+// Open opens a connection to the SQLite database.
func Open(dbPath string) (*sql.DB, error) {
return sql.Open("sqlite", "file:"+dbPath+"?_pragma=journal_mode%3DWAL")
}
// VerifySchema checks whether the schema has been initialised and initialises it
-// if not
+// if not.
func InitialiseDatabase(dbConn *sql.DB) error {
var name string
err := dbConn.QueryRow("SELECT name FROM sqlite_master WHERE type='table' AND name='users'").Scan(&name)
@@ -48,7 +48,7 @@ var migrations = [...]migration{
},
}
-// Migrate runs all pending migrations
+// Migrate runs all pending migrations.
func Migrate(db *sql.DB) error {
version := getSchemaVersion(db)
for nextMigration := version + 1; nextMigration < len(migrations); nextMigration++ {
@@ -123,7 +123,7 @@ func undoMigration(db *sql.DB, migrationIdx int) (err error) {
return updateSchemaVersion(tx, migrationIdx-1)
}
-// getSchemaVersion returns the schema version from the database
+// getSchemaVersion returns the schema version from the database.
func getSchemaVersion(db *sql.DB) int {
row := db.QueryRowContext(context.Background(), `SELECT version FROM schema_migrations LIMIT 1;`)
var version int
@@ -133,7 +133,7 @@ func getSchemaVersion(db *sql.DB) int {
return version
}
-// updateSchemaVersion sets the version to the provided int
+// updateSchemaVersion sets the version to the provided int.
func updateSchemaVersion(tx *sql.Tx, version int) error {
if version < 0 {
// Do not try to use the schema_migrations table in a schema version where it doesn't exist
@@ -9,7 +9,7 @@ import (
"sync"
)
-// DeleteProject deletes a project from the database
+// DeleteProject deletes a project from the database.
func DeleteProject(db *sql.DB, mu *sync.Mutex, id string) error {
mu.Lock()
defer mu.Unlock()
@@ -21,7 +21,7 @@ func DeleteProject(db *sql.DB, mu *sync.Mutex, id string) error {
return err
}
-// GetProject returns a project from the database
+// GetProject returns a project from the database.
func GetProject(db *sql.DB, id string) (map[string]string, error) {
var name, forge, url, version string
err := db.QueryRow("SELECT name, forge, url, version FROM projects WHERE id = ?", id).Scan(&name, &forge, &url, &version)
@@ -38,13 +38,13 @@ func GetProject(db *sql.DB, id string) (map[string]string, error) {
return project, nil
}
-// UpsertProject adds or updates a project in the database
+// UpsertProject adds or updates a project in the database.
func UpsertProject(db *sql.DB, mu *sync.Mutex, id, url, name, forge, running string) error {
mu.Lock()
defer mu.Unlock()
_, err := db.Exec(`INSERT INTO projects (id, url, name, forge, version)
VALUES (?, ?, ?, ?, ?)
- ON CONFLICT(id) DO
+ ON CONFLICT(id) DO
UPDATE SET
name = excluded.name,
forge = excluded.forge,
@@ -52,7 +52,7 @@ func UpsertProject(db *sql.DB, mu *sync.Mutex, id, url, name, forge, running str
return err
}
-// GetProjects returns a list of all projects in the database
+// GetProjects returns a list of all projects in the database.
func GetProjects(db *sql.DB) ([]map[string]string, error) {
rows, err := db.Query("SELECT id, name, url, forge, version FROM projects")
if err != nil {
@@ -10,13 +10,13 @@ import (
)
// UpsertRelease adds or updates a release for a project with a given ID in the
-// database
+// database.
func UpsertRelease(db *sql.DB, mu *sync.Mutex, id, projectID, url, tag, content, date string) error {
mu.Lock()
defer mu.Unlock()
_, err := db.Exec(`INSERT INTO releases (id, project_id, url, tag, content, date)
VALUES (?, ?, ?, ?, ?, ?)
- ON CONFLICT(id) DO
+ ON CONFLICT(id) DO
UPDATE SET
url = excluded.url,
content = excluded.content,
@@ -26,7 +26,7 @@ func UpsertRelease(db *sql.DB, mu *sync.Mutex, id, projectID, url, tag, content,
return err
}
-// GetReleases returns all releases for a project with a given id from the database
+// GetReleases returns all releases for a project with a given id from the database.
func GetReleases(db *sql.DB, projectID string) ([]map[string]string, error) {
rows, err := db.Query(`SELECT id, url, tag, content, date FROM releases WHERE project_id = ?`, projectID)
if err != nil {
@@ -10,7 +10,7 @@ import (
)
// DeleteUser deletes specific user from the database and returns an error if it
-// fails
+// fails.
func DeleteUser(db *sql.DB, user string) error {
mutex.Lock()
defer mutex.Unlock()
@@ -18,7 +18,7 @@ func DeleteUser(db *sql.DB, user string) error {
return err
}
-// CreateUser creates a new user in the database and returns an error if it fails
+// CreateUser creates a new user in the database and returns an error if it fails.
func CreateUser(db *sql.DB, username, hash, salt string) error {
mutex.Lock()
defer mutex.Unlock()
@@ -27,7 +27,7 @@ func CreateUser(db *sql.DB, username, hash, salt string) error {
}
// GetUser returns a user's hash and salt from the database as strings and
-// returns an error if it fails
+// returns an error if it fails.
func GetUser(db *sql.DB, username string) (string, string, error) {
var hash, salt string
err := db.QueryRow("SELECT hash, salt FROM users WHERE username = ?", username).Scan(&hash, &salt)
@@ -35,7 +35,7 @@ func GetUser(db *sql.DB, username string) (string, string, error) {
}
// GetUsers returns a list of all users in the database as a slice of strings
-// and returns an error if it fails
+// and returns an error if it fails.
func GetUsers(db *sql.DB) ([]string, error) {
rows, err := db.Query("SELECT username FROM users")
if err != nil {
@@ -57,7 +57,7 @@ func GetUsers(db *sql.DB) ([]string, error) {
}
// GetSession accepts a session ID and returns the username associated with it
-// and an error
+// and an error.
func GetSession(db *sql.DB, session string) (string, time.Time, error) {
var username string
var expiresString string
@@ -83,7 +83,7 @@ func InvalidateSession(db *sql.DB, session string, expiry time.Time) error {
}
// CreateSession creates a new session in the database and returns an error if
-// it fails
+// it fails.
func CreateSession(db *sql.DB, username, token string, expiry time.Time) error {
mutex.Lock()
defer mutex.Unlock()
@@ -40,7 +40,7 @@ type Release struct {
Date time.Time
}
-// GetReleases returns a list of all releases for a project from the database
+// GetReleases returns a list of all releases for a project from the database.
func GetReleases(dbConn *sql.DB, mu *sync.Mutex, proj Project) (Project, error) {
proj.ID = GenProjectID(proj.URL, proj.Name, proj.Forge)
@@ -67,7 +67,7 @@ func GetReleases(dbConn *sql.DB, mu *sync.Mutex, proj Project) (Project, error)
return proj, nil
}
-// fetchReleases fetches releases from a project's forge given its URI
+// fetchReleases fetches releases from a project's forge given its URI.
func fetchReleases(dbConn *sql.DB, mu *sync.Mutex, p Project) (Project, error) {
var err error
switch p.Forge {
@@ -129,7 +129,7 @@ func SortProjects(projects []Project) []Project {
return projects
}
-// upsertReleases updates or inserts a release in the database
+// upsertReleases updates or inserts a release in the database.
func upsertReleases(dbConn *sql.DB, mu *sync.Mutex, projID string, releases []Release) error {
for _, release := range releases {
date := release.Date.Format("2006-01-02 15:04:05")
@@ -142,13 +142,13 @@ func upsertReleases(dbConn *sql.DB, mu *sync.Mutex, projID string, releases []Re
return nil
}
-// GenReleaseID generates a likely-unique ID from its project's URL, its release's URL, and its tag
+// GenReleaseID generates a likely-unique ID from its project's URL, its release's URL, and its tag.
func GenReleaseID(projectURL, releaseURL, tag string) string {
idByte := sha256.Sum256([]byte(projectURL + releaseURL + tag))
return fmt.Sprintf("%x", idByte)
}
-// GenProjectID generates a likely-unique ID from a project's URI, name, and forge
+// GenProjectID generates a likely-unique ID from a project's URI, name, and forge.
func GenProjectID(url, name, forge string) string {
idByte := sha256.Sum256([]byte(url + name + forge))
return fmt.Sprintf("%x", idByte)
@@ -228,7 +228,7 @@ func RefreshLoop(dbConn *sql.DB, mu *sync.Mutex, interval int, manualRefresh, re
}
}
-// GetProject returns a project from the database
+// GetProject returns a project from the database.
func GetProject(dbConn *sql.DB, proj Project) (Project, error) {
projectDB, err := db.GetProject(dbConn, proj.ID)
if err != nil && errors.Is(err, sql.ErrNoRows) {
@@ -246,7 +246,7 @@ func GetProject(dbConn *sql.DB, proj Project) (Project, error) {
return p, err
}
-// GetProjectWithReleases returns a single project from the database along with its releases
+// GetProjectWithReleases returns a single project from the database along with its releases.
func GetProjectWithReleases(dbConn *sql.DB, mu *sync.Mutex, proj Project) (Project, error) {
project, err := GetProject(dbConn, proj)
if err != nil {
@@ -256,7 +256,7 @@ func GetProjectWithReleases(dbConn *sql.DB, mu *sync.Mutex, proj Project) (Proje
return GetReleases(dbConn, mu, project)
}
-// GetProjects returns a list of all projects from the database
+// GetProjects returns a list of all projects from the database.
func GetProjects(dbConn *sql.DB) ([]Project, error) {
projectsDB, err := db.GetProjects(dbConn)
if err != nil {
@@ -278,7 +278,7 @@ func GetProjects(dbConn *sql.DB) ([]Project, error) {
}
// GetProjectsWithReleases returns a list of all projects and all their releases
-// from the database
+// from the database.
func GetProjectsWithReleases(dbConn *sql.DB, mu *sync.Mutex) ([]Project, error) {
projects, err := GetProjects(dbConn)
if err != nil {
@@ -88,7 +88,7 @@ func InvalidateSession(dbConn *sql.DB, session string) error {
}
// CreateSession accepts a username, generates a token, stores it in the
-// database, and returns it
+// database, and returns it.
func CreateSession(dbConn *sql.DB, username string) (string, time.Time, error) {
token, err := generateSalt()
if err != nil {
@@ -33,7 +33,6 @@ type Handler struct {
//go:embed static
var fs embed.FS
-// bmUGC = bluemonday.UGCPolicy()
var bmStrict = bluemonday.StrictPolicy()
func (h Handler) RootHandler(w http.ResponseWriter, r *http.Request) {