Improve config and comments
This commit is contained in:
parent
78056d8b48
commit
7fdb0bf0f4
5 changed files with 18 additions and 17 deletions
|
@ -27,9 +27,9 @@ func Register(w http.ResponseWriter, r *http.Request) {
|
|||
password = strings.TrimSpace(password)
|
||||
if !(validEmail(email) && validPass(password) && !storage.Data.Taken(email)) {
|
||||
slog.Debug("outcome",
|
||||
"email", validEmail(email),
|
||||
"pass", validPass(password),
|
||||
"taken", !storage.Data.Taken(email))
|
||||
"valid_email", validEmail(email),
|
||||
"valid_pass", validPass(password),
|
||||
"taken_email", storage.Data.Taken(email))
|
||||
http.Error(w, "invalid auth credentials", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ var findUserCmd = &cobra.Command{
|
|||
Run: findUser,
|
||||
}
|
||||
|
||||
// TODO: Better name.
|
||||
func findUser(cmd *cobra.Command, args []string) {
|
||||
var user storage.User
|
||||
var ok bool
|
||||
|
@ -28,7 +27,7 @@ func findUser(cmd *cobra.Command, args []string) {
|
|||
} else if args[0] == "uuid" {
|
||||
user, ok = storage.Data.ById(args[1])
|
||||
} else {
|
||||
fmt.Println("expected email or uuid")
|
||||
fmt.Println("Expected email or uuid")
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
|
|
|
@ -30,7 +30,6 @@ var verifyCmd = &cobra.Command{
|
|||
Run: verifyFunc,
|
||||
}
|
||||
|
||||
// TODO: Needs a better name?
|
||||
func verifyFunc(cmd *cobra.Command, args []string) {
|
||||
if verifyToken == "" {
|
||||
fmt.Println("Empty token supplied!")
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// Config stores app configuration
|
||||
type Config struct {
|
||||
Port int `json:"port"`
|
||||
KeyFile string `json:"key-file"`
|
||||
|
@ -27,25 +28,27 @@ var (
|
|||
Cfg Config
|
||||
)
|
||||
|
||||
func Load(filename string) error {
|
||||
// Load parses a JSON-formatted configuration file
|
||||
func load(filename string) (Config, error) {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
return Config{}, err
|
||||
}
|
||||
temp_config := DefaultConfig
|
||||
err = json.Unmarshal(data, &temp_config)
|
||||
conf := DefaultConfig
|
||||
err = json.Unmarshal(data, &conf)
|
||||
if err != nil {
|
||||
return err
|
||||
return Config{}, err
|
||||
}
|
||||
Cfg = temp_config
|
||||
slog.Debug("Loaded config", "file", filename, "config", Cfg)
|
||||
return nil
|
||||
slog.Debug("Loaded config", "file", filename, "config", conf)
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
// MustLoad handles initial configuration loading
|
||||
func MustLoad(filename string) {
|
||||
err := Load(filename)
|
||||
conf, err := load(filename)
|
||||
if err != nil {
|
||||
slog.Error("error initially loading config", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Cfg = conf
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const create string = `
|
|||
PRIMARY KEY("uuid")
|
||||
);`
|
||||
|
||||
// SQLiteStorage is a storage.Storage implementation with SQLite3
|
||||
// SQLiteStorage is a Storage implementation with SQLite3
|
||||
type SQLiteStorage struct {
|
||||
db *sql.DB
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue