From f340f74e1d06aa588dd075f3922505878915da01 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Thu, 26 Sep 2024 22:54:50 +0200 Subject: init --- .gitignore | 1 + Makefile | 8 +++++ go.mod | 3 ++ ideas.html | 56 +++++++++++++++++++++++++++++++++++ main.go | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 166 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 go.mod create mode 100644 ideas.html create mode 100644 main.go 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 @@ + + + + + + Ideas + + + + + + + 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) + } +} -- cgit v1.2.3