diff --git a/comments.go b/comments.go new file mode 100644 index 0000000..4f128ab --- /dev/null +++ b/comments.go @@ -0,0 +1,73 @@ +package main + +import ( + "context" + "encoding/json" + "io" + "net/http" + "time" + + "git.home.dutchellie.nl/DutchEllie/proper-website-2/entity" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" +) + +func (a *application) Comment(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case "POST": + var comment entity.Comment + body, err := io.ReadAll(r.Body) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + err = json.Unmarshal(body, &comment) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + comment.PostDate = time.Now() + + if comment.Name == "" || comment.Message == "" { + a.WriteError(w, http.StatusBadRequest, "one or more fields empty") + return + } + + _, err = a.collection.InsertOne(context.Background(), comment) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + w.WriteHeader(200) + return + case "GET": + comments := make([]entity.Comment, 0) + filter := bson.D{} + sort := options.Find() + sort.SetSort(bson.D{{"time", -1}}) + cur, err := a.collection.Find(context.Background(), filter, sort) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + err = cur.All(context.Background(), &comments) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + jsondata, err := json.Marshal(comments) + if err != nil { + a.WriteError(w, http.StatusInternalServerError, err.Error()) + return + } + + w.WriteHeader(200) + w.Write(jsondata) + return + } +} + +func (a *application) WriteError(w http.ResponseWriter, code int, err string) { + w.WriteHeader(code) + w.Write([]byte(err)) +} diff --git a/components/aboutpage.go b/components/aboutpage.go index 7c5fc8e..d5cb344 100644 --- a/components/aboutpage.go +++ b/components/aboutpage.go @@ -1,6 +1,8 @@ package components -import "github.com/maxence-charriere/go-app/v9/pkg/app" +import ( + "github.com/maxence-charriere/go-app/v9/pkg/app" +) type AboutPage struct { app.Compo @@ -22,10 +24,26 @@ func (a *AboutPage) Render() app.UI { type aboutPanel struct { app.Compo + + aboutText string } func (a *aboutPanel) Render() app.UI { return app.Div().Body( - app.Raw(`

I am a 21 year old computer science student, living and studying in The Netherlands.

`), + app.Img().Src("/web/static/images/rin-1.gif").Styles(map[string]string{"width": "100px", "position": "absolute", "top": "10px", "right": "10px"}), + app.Raw(`

I am a 21 year old computer science student, living and studying in The Netherlands. I like Docker, Kubernetes and Golang! +
+I made this website because I was inspired again by the amazing Neocities pages that I discovered because of my friends. +They also have their own pages (you can find them on the friends tab, do check them out!) and I just had to get a good website of my own! +
+I am not that great at web development, especially design, but I love trying it regardless! +

+To say a bit more about me personally, I love all things computers. From servers to embedded devices! I love the cloud and all that it brings +(except for big megacorps, but alright) and it's my goal to work for a big cloud company! +
+Aside from career path ambitions, ボーカロイドはすきです! I love vocaloid and other Japanese music and culture!! +I also like Vtubers, especially from Hololive and it's my goal to one day finally understand them in their native language! +

+There is a lot more to say in words, but who cares about those! Have a look around my creative digital oasis and see what crazy stuff you can find!

`), ).Class("content") } diff --git a/components/guestbookform.go b/components/guestbookform.go new file mode 100644 index 0000000..105a578 --- /dev/null +++ b/components/guestbookform.go @@ -0,0 +1,58 @@ +package components + +import ( + "fmt" + + "github.com/maxence-charriere/go-app/v9/pkg/app" +) + +type guestbookForm struct { + app.Compo + + name string + message string + + OnSubmit func( + name string, + message string, + ) // Handler to implement which calls the api +} + +func (g *guestbookForm) Render() app.UI { + return app.Div().Body( + app.Form().Body( + app.Input(). + Type("text"). + Name("name"). + Placeholder("Name"). + Required(true). + OnInput(g.ValueTo(&g.name)). + Value(g.name), + app.Input(). + Type("text"). + Name("message"). + Placeholder("Message"). + Required(true). + OnInput(g.ValueTo(&g.message)). + Value(g.message), + app.Input(). + Type("submit"). + Name("submit"), + ).ID("form"). + OnSubmit(func(ctx app.Context, e app.Event) { + // This was to prevent the page from reloading + e.PreventDefault() + if g.name == "" || g.message == "" { + fmt.Printf("Error: one or more field(s) are empty. For now unhandled\n") + } + g.OnSubmit(g.name, g.message) + g.clear() + g.Update() + }), + ).Class("content") +} + +func (g *guestbookForm) clear() { + g.name = "" + g.message = "" +} diff --git a/components/guestbookpanel.go b/components/guestbookpanel.go new file mode 100644 index 0000000..3861e59 --- /dev/null +++ b/components/guestbookpanel.go @@ -0,0 +1,93 @@ +package components + +import ( + "encoding/json" + "io" + "net/http" + + "git.home.dutchellie.nl/DutchEllie/proper-website-2/entity" + "github.com/maxence-charriere/go-app/v9/pkg/app" +) + +/* +What is this supposed to do: +- It should call on the API to give it a certain number of comments, in the range x to y (this has to be implemented in the api) +- When it has called that, it should display those +- Dynamic links are there to navigate the user along the pages +- Comments are shown dynamically +- This panel can be shown or hidden (maybe) + +AND VERY IMPORTANT! +- If a user submits a new comment, automatically put it on the page, no reloading + +*/ +type guestbookPanel struct { + app.Compo + + comments []entity.Comment + CommentUpdate bool +} + +func newGuestbookPanel() *guestbookPanel { + return &guestbookPanel{} +} + +func (g *guestbookPanel) Render() app.UI { + g.LoadComments() + return app.Div().Body( + app.Range(g.comments).Slice(func(i int) app.UI { + return &guestbookComment{ + Comment: g.comments[i], + } + }), + ).Class("content") +} + +func (g *guestbookPanel) LoadComments() { + // TODO: maybe you can put this in a localbrowser storage? + url := "/api/comment" + res, err := http.Get(url) + if err != nil { + app.Log(err) + return + } + defer res.Body.Close() + jsondata, err := io.ReadAll(res.Body) + if err != nil { + app.Log(err) + return + } + + err = json.Unmarshal(jsondata, &g.comments) + if err != nil { + app.Log(err) + return + } +} + +func (g *guestbookPanel) OnMount(ctx app.Context) { + //g.LoadComments() +} + +func (g *guestbookPanel) OnUpdate(ctx app.Context) { + if g.CommentUpdate { + g.LoadComments() + g.Update() + g.CommentUpdate = false + } +} + +type guestbookComment struct { + app.Compo + + Comment entity.Comment +} + +func (c *guestbookComment) Render() app.UI { + return app.Div().Body( + app.Span().Text("Name:").Style("font-weight", "800"), + app.P().Text(c.Comment.Name), + app.Span().Text("Comment:").Style("font-weight", "800"), + app.P().Text(c.Comment.Message), + ).Class("comment") +} diff --git a/components/homepage.go b/components/homepage.go index 25b0c8d..70e8c43 100644 --- a/components/homepage.go +++ b/components/homepage.go @@ -1,27 +1,60 @@ package components import ( + "bytes" + "encoding/json" + "fmt" + "net/http" + + "git.home.dutchellie.nl/DutchEllie/proper-website-2/entity" "github.com/maxence-charriere/go-app/v9/pkg/app" ) type Homepage struct { app.Compo - content *contentView + showGuestbook bool + guestbookUpdated bool } func NewHomepage() *Homepage { - p1 := newHomePanel() - c := newContentView(p1) - return &Homepage{content: c} + return &Homepage{showGuestbook: true, guestbookUpdated: false} } func (p *Homepage) Render() app.UI { + gbp := newGuestbookPanel() return app.Div().Body( &header{}, app.Div().Body( newNavbar(), - newHomePanel(), + &homePanel{ + onShowClick: func() { + p.showGuestbook = !p.showGuestbook + }, + }, + &guestbookForm{ + OnSubmit: func(name, message string) { + var comment entity.Comment + comment.Name = name + comment.Message = message + + jsondata, err := json.Marshal(comment) + if err != nil { + fmt.Printf("err: %v\n", err) + return + } + url := "/api/comment" + req, err := http.Post(url, "application/json", bytes.NewBuffer(jsondata)) + if err != nil { + fmt.Printf("err: %v\n", err) + return + } + if req.StatusCode == 200 { + } + defer req.Body.Close() + }, + }, + app.If(p.showGuestbook, gbp), ).Class("main"), ) } diff --git a/components/homepanel.go b/components/homepanel.go index e3f0489..73edb4c 100644 --- a/components/homepanel.go +++ b/components/homepanel.go @@ -4,6 +4,8 @@ import "github.com/maxence-charriere/go-app/v9/pkg/app" type homePanel struct { app.Compo + + onShowClick func() } func newHomePanel() *homePanel { @@ -20,6 +22,10 @@ Please enjoy yourself and do sign the guestbook!!

`), app.Div().Body( app.P().Text("Please sign my guestbook!").Style("font-size", "0.8em"), app.Img().Src("/web/static/images/email3.gif").Style("width", "40px").Style("position", "absolute").Style("bottom", "0px").Style("right", "0px"), - ).Style("position", "absolute").Style("bottom", "5px").Style("right", "5px"), + ).Style("position", "absolute").Style("bottom", "5px").Style("right", "5px"). + OnClick(func(ctx app.Context, e app.Event) { + e.PreventDefault() + p.onShowClick() + }), ).Class("content") } diff --git a/components/updater.go b/components/updater.go new file mode 100644 index 0000000..d5f32b9 --- /dev/null +++ b/components/updater.go @@ -0,0 +1,27 @@ +package components + +import "github.com/maxence-charriere/go-app/v9/pkg/app" + +type updater struct { + app.Compo + + updateAvailable bool +} + +func (u *updater) onAppUpdate(ctx app.Context) { + u.updateAvailable = ctx.AppUpdateAvailable() +} + +func (u *updater) Render() app.UI { + return app.Div().Body( + app.If(u.updateAvailable, + app.Div().Body( + app.P().Text("An update for this website is available! Please click here to reload!"), + ).Styles(map[string]string{"position": "absolute", "width": "100px", "bottom": "10px", "right": "10px"}).OnClick(u.onUpdateClick), + ), + ) +} + +func (u *updater) onUpdateClick(ctx app.Context, e app.Event) { + ctx.Reload() +} diff --git a/entity/comment.go b/entity/comment.go new file mode 100644 index 0000000..8157afb --- /dev/null +++ b/entity/comment.go @@ -0,0 +1,12 @@ +package entity + +import "time" + +type Comment struct { + ID string `json:"id,omitempty" bson:"_id,omitempty"` + Name string `json:"name" bson:"name"` + Website string `json:"website,omitempty" bson:"website,omitempty"` + Email string `json:"email,omitempty" bson:"email,omitempty"` + Message string `json:"message" bson:"message"` + PostDate time.Time `json:"time" bson:"time"` +} diff --git a/go.mod b/go.mod index 949b38e..854c9fc 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,21 @@ module git.home.dutchellie.nl/DutchEllie/proper-website-2 go 1.17 require ( - github.com/google/uuid v1.3.0 // indirect - github.com/maxence-charriere/go-app/v9 v9.3.0 // indirect + github.com/maxence-charriere/go-app/v9 v9.3.0 + go.mongodb.org/mongo-driver v1.8.3 +) + +require ( + github.com/go-stack/stack v1.8.0 // indirect + github.com/golang/snappy v0.0.1 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/klauspost/compress v1.13.6 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.0.2 // indirect + github.com/xdg-go/stringprep v1.0.2 // indirect + github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect + golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect + golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect + golang.org/x/text v0.3.6 // indirect ) diff --git a/go.sum b/go.sum index 99eac09..ce62fcf 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,68 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomarkdown/markdown v0.0.0-20210408062403-ad838ccf8cdd/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU= +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/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/maxence-charriere/go-app/v9 v9.3.0 h1:PWNZWcme5hnMR9/cSdSRv+9WvPowETj0qhfy+3HCQRM= github.com/maxence-charriere/go-app/v9 v9.3.0/go.mod h1:zo0n1kh4OMKn7P+MrTUUi7QwUMU2HOfHsZ293TITtxI= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w= +github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= +github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc= +github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= +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= +go.mongodb.org/mongo-driver v1.8.3 h1:TDKlTkGDKm9kkJVUOAXDK5/fkqKHJVwYQSpoRfB43R4= +go.mongodb.org/mongo-driver v1.8.3/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f h1:aZp0e2vLN4MToVqnjNEYEtrEA8RH8U8FN1CU7JgqsPU= +golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +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= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index e4c428c..2fd1d63 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,24 @@ package main import ( + "context" + "fmt" "log" "net/http" "git.home.dutchellie.nl/DutchEllie/proper-website-2/components" "github.com/maxence-charriere/go-app/v9/pkg/app" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readpref" ) +type application struct { + client *mongo.Client + database *mongo.Database + collection *mongo.Collection +} + func main() { homepage := components.NewHomepage() aboutpage := components.NewAboutPage() @@ -19,6 +30,32 @@ func main() { // It exits immediately on the server side app.RunWhenOnBrowser() + uri := "mongodb+srv://guestbook-database:5WUDzpvBKBBiiMCy@cluster0.wtt64.mongodb.net/myFirstDatabase?retryWrites=true&w=majority" + + client, err := mongo.Connect(context.TODO(), options.Client().ApplyURI(uri)) + if err != nil { + fmt.Println(err) + return + } + defer func() { + if err = client.Disconnect(context.TODO()); err != nil { + panic(err) + } + }() + + // Ping the primary + if err := client.Ping(context.TODO(), readpref.Primary()); err != nil { + panic(err) + } + db := client.Database("guestbook") + coll := db.Collection("comments") + + apiapp := &application{ + client: client, + database: db, + collection: coll, + } + http.Handle("/", &app.Handler{ Name: "Internetica Galactica", Description: "A 1990's style PWA!", @@ -30,6 +67,7 @@ func main() { }, CacheableResources: []string{}, }) + http.HandleFunc("/api/comment", apiapp.Comment) if err := http.ListenAndServe(":8000", nil); err != nil { log.Fatal(err) diff --git a/web/static/images/rin-1.gif b/web/static/images/rin-1.gif new file mode 100644 index 0000000..c196128 Binary files /dev/null and b/web/static/images/rin-1.gif differ diff --git a/web/static/pages/aboutpage.html b/web/static/pages/aboutpage.html new file mode 100644 index 0000000..b5e9414 --- /dev/null +++ b/web/static/pages/aboutpage.html @@ -0,0 +1,14 @@ +

I am a 21 year old computer science student, living and studying in The Netherlands. I like Docker, Kubernetes and Golang! +
+I made this website because I was inspired again by the amazing Neocities pages that I discovered because of my friends. +They also have their own pages (you can find them on the friends tab, do check them out!) and I just had to get a good website of my own! +
+I am not that great at web development, especially design, but I love trying it regardless! +

+To say a bit more about me personally, I love all things computers. From servers to embedded devices! I love the cloud and all that it brings +(except for big megacorps, but alright) and it's my goal to work for a big cloud company! +
+Aside from career path ambitions, ボーカロイドはすきです! I love vocaloid and other Japanese music and culture!! +I also like Vtubers, especially from Hololive and it's my goal to one day finally understand them in their native language! +

+There is a lot more to say in words, but who cares about those! Have a look around my creative digital oasis and see what crazy stuff you can find!

\ No newline at end of file diff --git a/web/static/style.css b/web/static/style.css index 5876202..77d564d 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -62,6 +62,13 @@ body { margin-bottom: 5px; } +.comment { + border: 2px solid; + border-radius: 3px; + border-color: aliceblue; + padding: 5px; +} + .p-h1 { font-family: anisha; font-size: 3em;