aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile8
-rw-r--r--go.mod3
-rw-r--r--ideas.html56
-rw-r--r--main.go98
5 files changed, 166 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3fec32c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+tmp/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4c6863a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+VERSION= $(shell git describe --tags)
+LDFLAGS = -X "main.airVersion=$(VVERSION)"
+
+build:
+ go build -ldflags '$(LDFLAGS)'
+
+install:
+ go install -ldflags '$(LDFLAGS)'
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..2ceea7b
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module ideez
+
+go 1.23.1
diff --git a/ideas.html b/ideas.html
new file mode 100644
index 0000000..14e86d3
--- /dev/null
+++ b/ideas.html
@@ -0,0 +1,56 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Ideas</title>
+ <style>
+
+.idea {
+ border: solid 2px black;
+ border-radius: 5px;
+ padding: 4px;
+ margin-bottom: 1em;
+ width: 50%;
+}
+.title {
+ margin-left: 1em;
+ margin-bottom: 0;
+ display: inline;
+}
+.rating {
+ display: inline;
+ margin-left: 1em;
+}
+.description {
+ margin-left: .5em;
+ margin-top: .5em;
+ font-family: monospace;
+ font-size: 1.25em;
+}
+.creation {
+ margin-bottom: 0;
+}
+.author {
+ font-style: italic;
+}
+.date {
+ color: #bcbcbc;
+}
+
+ </style>
+</head>
+<body>
+ <ul>
+ {{ range .Ideas }}
+ <div class="idea">
+ <h2 class="title">{{.Title}}</h2>
+ <p class="rating">{{.Rating}}/5</p>
+ <p class="description">{{.Description}}</p>
+ <p class="creation">by <span class="author">{{.Author}}</span> on <span class="date">{{.CreatedAt}}</span></p>
+ </div>
+ {{ end }}
+ </ul>
+ <!--template-->
+</body>
+</html>
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..9f1383b
--- /dev/null
+++ b/main.go
@@ -0,0 +1,98 @@
+package main
+
+import (
+ _ "embed"
+ "fmt"
+ "html/template"
+ "log"
+ "net/http"
+)
+
+// File for persistent storage
+const DataFilename = "main.data"
+
+// layout for how the date should be output in html
+var DateLayout string = "02/01/2006 on 15:04"
+
+// template for listing out the ideas, should be bundled inside the executable
+//
+//go:embed ideas.html
+var ideas_html string
+
+// ToDo's
+// - [ ] Add a post
+// - [ ] Serialize data to a file
+// - [ ] Remove a post
+// - [x] Change the date format printing
+// - [ ] work with funcmaps in templates
+// - [ ] Put a reaction on a post
+
+// Represents an idea
+// CreatedAt is a formatted date string
+// out of 5 rating of the idea
+// formatted time string with DateLayout
+type Idea struct {
+ Title string
+ Description string
+ Author string
+ CreatedAt string
+}
+
+func main() {
+ var ideas []Idea
+
+ // Create a .data file in the cache directory
+ {
+ // data := os.Getenv("XDG_CACHE_HOME")
+ // if data == "" {
+ // data = "."
+ // }
+ // data = data + ""
+ //
+ // file, err := os.Create(data + "/" + DataFilename)
+ // if err != nil {
+ // panic(err)
+ // }
+ }
+ // hardcoded data
+ {
+ ideas = []Idea{
+ {
+ Title: "Better Keylogger",
+ Description: "Keylogger which records statistics about your typing.",
+ Author: "Me",
+ CreatedAt: "26/09/2024 on 14:51",
+ },
+ {
+ Title: "music tracker",
+ Description: "An app that can track music across multiple music apps such as spotify, apple music, deezer, etc.",
+ Author: "Me",
+ CreatedAt: "24/09/2024 on 14:32",
+ },
+ {
+ Title: "automated hosting",
+ Description: "Service to host a website where people can drag&drop their files and they are hosted, it also provides a subdomain automatically.",
+ Author: "Him",
+ },
+ }
+ }
+ // // Example of parsing a string into time with the layout
+ // CreatedAt: func() string {
+ // t, _ := time.Parse(DateLayout, "24/09/2024 on 14:40")
+ // return t.Format(DateLayout)
+
+ tmpl, err := template.New("mytemplate").Parse(ideas_html)
+ if err != nil {
+ log.Fatalln(err)
+ }
+
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ tmpl.Execute(w, struct{ Ideas []Idea }{ideas})
+ })
+
+ fmt.Println("Listening on http://localhost:8080")
+ err = http.ListenAndServe(":8080", nil)
+ if err != nil {
+ log.Fatalln(err)
+ }
+}