feat: add permissions on user create, CORS middleware, cors server playground.

This commit is contained in:
2026-04-24 10:55:40 +02:00
parent d629bd52eb
commit 2fd3a1d57b
8 changed files with 179 additions and 3 deletions
+16
View File
@@ -5,6 +5,7 @@ import (
"database/sql"
"flag"
"os"
"strings"
"sync"
"time"
@@ -48,6 +49,10 @@ type config struct {
password string
sender string
}
// Add a cors struct and trustedOrigins field with the type []string.
cors struct {
trustedOrigins []string
}
}
// Define an application struct to hold the dependencies for our HTTP handlers, helpers,
@@ -101,6 +106,17 @@ func main() {
flag.StringVar(&cfg.smtp.password, "smtp-password", "d06a774b484ca3", "SMTP password")
flag.StringVar(&cfg.smtp.sender, "smtp-sender", "Greenlight <no-reply@greenlight.debuggingjon.dev>", "SMTP sender")
// Use the flag.Func() function to process the -cors-trusted-origins command line
// flag. In this we use the strings.Fields() function to split the flag value into a
// slice based on whitespace characters and assign it to our config struct.
// Importantly, if the -cors-trusted-origins flag is not present, contains the empty
// string, or contains only whitespace, then strings.Fields() will return an empty
// []string slice.
flag.Func("cors-trusted-origins", "Trusted CORS origins (space separated)", func(val string) error {
cfg.cors.trustedOrigins = strings.Fields(val)
return nil
})
flag.Parse()
// Call the openDB() helper function (see below) to create the connection pool,