started the thingy
sophuwu sophie@skisiel.com
Fri, 19 Jul 2024 15:27:19 +0200
17 files changed,
249 insertions(+),
0 deletions(-)
jump to
A
.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml
A
.idea/dictionaries/sophuwu.xml
@@ -0,0 +1,3 @@
+<component name="ProjectDictionaryState"> + <dictionary name="sophuwu" /> +</component>
A
.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,5 @@
+<component name="InspectionProjectProfileManager"> + <profile version="1.0"> + <option name="myName" value="Project Default" /> + </profile> +</component>
A
.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager"> + <settings> + <option name="PROJECT_PROFILE" value="Default" /> + <option name="USE_PROJECT_PROFILE" value="false" /> + </settings> +</component>
A
.idea/misc.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="MarkdownSettingsMigration"> + <option name="stateVersion" value="1" /> + </component> + <component name="MaterialThemeProjectNewConfig"> + <option name="metadata"> + <MTProjectMetadataState> + <option name="migrated" value="true" /> + <option name="pristineConfig" value="false" /> + <option name="userId" value="-146c056c:190b5f322c9:-7ff7" /> + </MTProjectMetadataState> + </option> + <option name="titleBarState"> + <MTProjectTitleBarConfigState> + <option name="overrideColor" value="false" /> + </MTProjectTitleBarConfigState> + </option> + </component> + <component name="ProjectInspectionProfilesVisibleTreeState"> + <entry key="Project Default"> + <profile-state> + <expanded-state> + <State> + <id>Proofreading</id> + </State> + </expanded-state> + <selected-state> + <State> + <id>LanguageDetectionInspection</id> + </State> + </selected-state> + </profile-state> + </entry> + </component> + <component name="ReaderModeSettings"> + <option name="enableVisualFormatting" value="false" /> + <option name="increaseLineSpacing" value="true" /> + <option name="useActiveSchemeForVisualFormatting" value="false" /> + </component> +</project>
A
.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/myweb.iml" filepath="$PROJECT_DIR$/.idea/myweb.iml" /> + </modules> + </component> +</project>
A
.idea/myweb.iml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?> +<module type="WEB_MODULE" version="4"> + <component name="Go" enabled="true" /> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
A
.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project>
A
config.yaml
@@ -0,0 +1,20 @@
+Server: + Port: "8085" + IP: "127.0.0.1" + +Paths: + Static: "./static" + Templates: "./templates" + Media: "./media" + +Contact: + Name: "Sophie Kisiel" + Email: "sophie@sksiel.com" + Links: + - Name: "GitHub" + URL: "https://github.com/Sophuwu300" + +Website: + Title: "Sophie Kisiel" + Description: "Sophie Kisiel's personal website and blog." + Url: "https://skisiel.com"
A
config/config.go
@@ -0,0 +1,71 @@
+package config + +import ( + yaml "gopkg.in/yaml.v3" + "log" + "os" +) + +// Server is a struct that holds the configuration for the server +type Server struct { + Port string `yaml:"Port"` + IP string `yaml:"IP"` +} + +// Host is function that returns the host string +func (s Server) Host() string { + return s.IP + ":" + s.Port +} + +// Dirs is a struct that holds directories needed for the server +type Dirs struct { + Static string `yaml:"Static"` + Templates string `yaml:"Templates"` + Media string `yaml:"Media"` +} + +// Link is a struct that holds the configuration for a link +type Link struct { + Name string `yaml:"Name"` + URL string `yaml:"URL"` +} + +// ContactInfo is a struct that holds the configuration for the contact information +type ContactInfo struct { + Email string `yaml:"Email"` + Name string `yaml:"Name"` + Links []Link `yaml:"Links"` +} + +// WebInfo is a struct that holds the configuration for the website information +type WebInfo struct { + Title string `yaml:"Title"` + Description string `yaml:"Description"` + Url string `yaml:"Url"` +} + +// Config is a struct that holds the configuration for the server, directories, and contact information +type Config struct { + Server Server `yaml:"Server"` + Paths Dirs `yaml:"Paths"` + Contact ContactInfo `yaml:"Contact"` + Website WebInfo `yaml:"Website"` +} + +// Cfg is a variable that holds the configuration +var Cfg Config + +func init() { + var path string = "config.yaml" + if len(os.Args) > 1 { + path = os.Args[1] + } + file, err := os.ReadFile(path) + if err != nil { + log.Fatalf("Error opening config: %v", err) + } + err = yaml.Unmarshal(file, &Cfg) + if err != nil { + log.Fatalf("Error parsing config: %v", err) + } +}
A
go.mod
@@ -0,0 +1,5 @@
+module sophuwu.site/myweb + +go 1.22.5 + +require gopkg.in/yaml.v3 v3.0.1 // indirect
A
go.sum
@@ -0,0 +1,3 @@
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
A
main.go
@@ -0,0 +1,33 @@
+package main + +import ( + "html/template" + "log" + "net/http" + "path/filepath" + "sophuwu.site/myweb/config" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + + tpath := filepath.Join(config.Cfg.Paths.Templates, "*") + t := template.Must(template.ParseGlob(tpath)) + data := make(map[string]string) + data["Title"] = config.Cfg.Website.Title + data["WebsiteTitle"] = config.Cfg.Website.Title + data["Description"] = config.Cfg.Website.Description + data["Url"] = config.Cfg.Website.Url + r.URL.Path + + if err := t.ExecuteTemplate(w, "index", data); err != nil { + log.Println(err) + return + } + }) + + http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(config.Cfg.Paths.Static)))) + http.Handle("/media/", http.StripPrefix("/media/", http.FileServer(http.Dir(config.Cfg.Paths.Media)))) + + http.ListenAndServe(config.Cfg.Server.Host(), nil) + +}
A
templates/head.html
@@ -0,0 +1,11 @@
+{{ define "head" }} +<head> + <link rel="stylesheet" type="text/css" href="/static/style.css"> + <link rel="icon" type="image/ico" href="/static/favicon.ico"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>{{ .Title }}</title> + <meta content="{{ .Title }}" property="og:title"> + <meta content="{{ .Description }}" property="og:description"> + <meta content="{{ .Url }}" property="og:url"> +</head> +{{ end }}
A
templates/header.html
@@ -0,0 +1,5 @@
+{{ define "header" }} +<header> + <h1>{{ .WebsiteName }}</h1> +</header> +{{ end }}
A
templates/index.html
@@ -0,0 +1,14 @@
+{{ define "index" }} +<!DOCTYPE html> +<html lang="en"> +{{ template "head" . }} +<body> +{{ template "header" . }} +<main> + <p> + {{ .Description }} + </p> +</main> +</body> +</html> +{{ end }}