schema migration and account fixes
very close to rolling this out! just need to address some security concerns first
This commit is contained in:
parent
5566a795da
commit
570cdf6ce2
20 changed files with 641 additions and 392 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/pelletier/go-toml/v2"
|
||||
|
@ -57,13 +56,13 @@ var Config = func() config {
|
|||
|
||||
err = toml.Unmarshal([]byte(data), &config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Failed to parse configuration file: %s\n", err.Error())
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Failed to parse configuration file: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = handleConfigOverrides(&config)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Failed to parse environment variable %s\n", err.Error())
|
||||
fmt.Fprintf(os.Stderr, "FATAL: Failed to parse environment variable %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -92,30 +91,4 @@ func handleConfigOverrides(config *config) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
var Args = func() map[string]string {
|
||||
args := map[string]string{}
|
||||
|
||||
index := 0
|
||||
for index < len(os.Args[1:]) {
|
||||
arg := os.Args[index + 1]
|
||||
if !strings.HasPrefix(arg, "-") {
|
||||
fmt.Printf("FATAL: Parameters must follow an argument (%s).\n", arg)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if index + 3 > len(os.Args) || strings.HasPrefix(os.Args[index + 2], "-") {
|
||||
args[arg[1:]] = "true"
|
||||
index += 1
|
||||
continue
|
||||
}
|
||||
|
||||
val := os.Args[index + 2]
|
||||
args[arg[1:]] = val
|
||||
// fmt.Printf("%s: %s\n", arg[1:], val)
|
||||
index += 2
|
||||
}
|
||||
|
||||
return args
|
||||
}()
|
||||
|
||||
var DB *sqlx.DB
|
||||
|
|
|
@ -58,12 +58,12 @@ func DefaultHeaders(next http.Handler) http.Handler {
|
|||
|
||||
type LoggingResponseWriter struct {
|
||||
http.ResponseWriter
|
||||
Code int
|
||||
Status int
|
||||
}
|
||||
|
||||
func (lrw *LoggingResponseWriter) WriteHeader(code int) {
|
||||
lrw.Code = code
|
||||
lrw.ResponseWriter.WriteHeader(code)
|
||||
func (lrw *LoggingResponseWriter) WriteHeader(status int) {
|
||||
lrw.Status = status
|
||||
lrw.ResponseWriter.WriteHeader(status)
|
||||
}
|
||||
|
||||
func HTTPLog(next http.Handler) http.Handler {
|
||||
|
@ -81,19 +81,19 @@ func HTTPLog(next http.Handler) http.Handler {
|
|||
elapsed = strconv.Itoa(difference)
|
||||
}
|
||||
|
||||
codeColour := colour.Reset
|
||||
statusColour := colour.Reset
|
||||
|
||||
if lrw.Code - 600 <= 0 { codeColour = colour.Red }
|
||||
if lrw.Code - 500 <= 0 { codeColour = colour.Yellow }
|
||||
if lrw.Code - 400 <= 0 { codeColour = colour.White }
|
||||
if lrw.Code - 300 <= 0 { codeColour = colour.Green }
|
||||
if lrw.Status - 600 <= 0 { statusColour = colour.Red }
|
||||
if lrw.Status - 500 <= 0 { statusColour = colour.Yellow }
|
||||
if lrw.Status - 400 <= 0 { statusColour = colour.White }
|
||||
if lrw.Status - 300 <= 0 { statusColour = colour.Green }
|
||||
|
||||
fmt.Printf("[%s] %s %s - %s%d%s (%sms) (%s)\n",
|
||||
after.Format(time.UnixDate),
|
||||
r.Method,
|
||||
r.URL.Path,
|
||||
codeColour,
|
||||
lrw.Code,
|
||||
statusColour,
|
||||
lrw.Status,
|
||||
colour.Reset,
|
||||
elapsed,
|
||||
r.Header["User-Agent"][0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue