From 7b15aab7ecae5122c02726d983970aa8045af926 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sun, 16 Jun 2024 06:46:44 -0500 Subject: [PATCH] SimpleApp Started work on the actual stuff Gave up on Valkey (for right now) --- go.mod | 11 +++++++---- go.sum | 12 ++++++------ internal/backend/app.go | 24 ++++++++++++++++++++++++ internal/backend/darkstorm.go | 4 ++++ internal/backend/darkstorm_test.go | 17 +---------------- internal/backend/db/sql.go | 6 ++++++ internal/backend/db/valkey.go | 12 +++++++++++- main.go | 18 ++++++++++++++++++ 8 files changed, 77 insertions(+), 27 deletions(-) create mode 100644 internal/backend/db/sql.go diff --git a/go.mod b/go.mod index b115052..43bc30a 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,17 @@ module github.com/CalebQ42/darkstorm-server go 1.22.3 require ( - github.com/google/uuid v1.6.0 - golang.org/x/crypto v0.24.0 github.com/golang-jwt/jwt/v5 v5.2.1 - go.mongodb.org/mongo-driver v1.15.0 + github.com/google/uuid v1.6.0 + go.mongodb.org/mongo-driver v1.15.1 + golang.org/x/crypto v0.24.0 ) +require github.com/google/go-cmp v0.6.0 // indirect + require ( github.com/golang/snappy v0.0.1 // indirect + github.com/joho/godotenv v1.5.1 // indirect github.com/klauspost/compress v1.13.6 // indirect github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect @@ -18,6 +21,6 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/text v0.16.0 // indirect golang.org/x/sys v0.21.0 // indirect + golang.org/x/text v0.16.0 // indirect ) diff --git a/go.sum b/go.sum index ea5a8fd..d4401a0 100644 --- a/go.sum +++ b/go.sum @@ -4,10 +4,12 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe h1:iruDEfMl2E6fbMZ9s0scYfZQ84/6SPL6zC8ACM2oIL0= @@ -21,8 +23,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= -go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= +go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= @@ -54,5 +56,3 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/backend/app.go b/internal/backend/app.go index 3db5d1c..0a3d5bf 100644 --- a/internal/backend/app.go +++ b/internal/backend/app.go @@ -14,3 +14,27 @@ type ExtendedApp interface { // Alternatively, use Backend.HandleFunc for more customizability Extension(http.ResponseWriter, *http.Request) } + +type simpleApp struct { + countTab CountTable + crashTab CrashTable + appID string +} + +func NewSimpleApp(appID string, countTable CountTable, crashTable CrashTable) App { + return &simpleApp{ + appID: appID, + countTab: countTable, + crashTab: crashTable, + } +} + +func (s *simpleApp) AppID() string { + return s.appID +} +func (s *simpleApp) CountTable() CountTable { + return s.countTab +} +func (s *simpleApp) CrashTable() CrashTable { + return s.crashTab +} diff --git a/internal/backend/darkstorm.go b/internal/backend/darkstorm.go index 1b9aa57..d5e86d8 100644 --- a/internal/backend/darkstorm.go +++ b/internal/backend/darkstorm.go @@ -76,6 +76,10 @@ func (b *Backend) cleanupLoop() { } } +func (b *Backend) ServeHTTP(w http.ResponseWriter, r *http.Request) { + b.m.ServeHTTP(w, r) +} + func getDate(t time.Time) int { return (t.Year() * 10000) + (int(t.Month()) * 100) + t.Day() } diff --git a/internal/backend/darkstorm_test.go b/internal/backend/darkstorm_test.go index c33a15a..476153f 100644 --- a/internal/backend/darkstorm_test.go +++ b/internal/backend/darkstorm_test.go @@ -1,23 +1,8 @@ -package backend +package backend_test import ( - "fmt" "testing" - "time" - - "github.com/google/uuid" ) func TestStuff(t *testing.T) { - for i := 0; i < 50; i++ { - go func() { - id, err := uuid.NewV7() - if err != nil { - fmt.Println(err) - } - fmt.Println(id.String()) - }() - } - time.Sleep(3 * time.Second) - t.Fatal("end") } diff --git a/internal/backend/db/sql.go b/internal/backend/db/sql.go new file mode 100644 index 0000000..ff2015b --- /dev/null +++ b/internal/backend/db/sql.go @@ -0,0 +1,6 @@ +package db + +/* +TODO +I don't like SQL, lol. +*/ \ No newline at end of file diff --git a/internal/backend/db/valkey.go b/internal/backend/db/valkey.go index 10060e9..9666e43 100644 --- a/internal/backend/db/valkey.go +++ b/internal/backend/db/valkey.go @@ -1 +1,11 @@ -package db \ No newline at end of file +package db + +/* +TODO +Currently there isn't a clean way to implement this (as far as I can tell). +valkey-go relies on an internal library for it's command builder, which makes it impossible to +use properly for generics without manually writing out the Index command. I could probably do this, but +it's a pain. +valkey-go does have a Generic Object Mapping library (valkey-go/om), but it requires a Version field +on every struct which would be confusing if I did add it to all my structs and Go doesn't allow anonymous generics inside structs +*/ \ No newline at end of file diff --git a/main.go b/main.go index da29a2c..b476897 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,22 @@ package main +import ( + "crypto/tls" + "flag" + "log" +) + func main() { + mongoURL := flag.String("mongo", "", "Enables MongoDB usage for darkstorm-backend.") + webRoot := flag.String("web-root", "", "Sets root directory of web server.") + flag.Parse() + if flag.NArg() != 1 { + log.Fatal("You must specify key directory. ex: darkstorm-server /etc/web-keys") + } + if *mongoURL != "" { + } + mongoCert, err := tls.LoadX509KeyPair(flag.Arg(0)+"mongo.pem", flag.Arg(0)+"key.pem") + if err != nil { + + } }