summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--assets/style.css32
-rw-r--r--assets/tmpl/index.html53
-rw-r--r--getwtxt.json5
-rw-r--r--handlers.go8
-rw-r--r--init.go31
-rw-r--r--types.go16
6 files changed, 123 insertions, 22 deletions
diff --git a/assets/style.css b/assets/style.css
index e148bda..5f62e1c 100644
--- a/assets/style.css
+++ b/assets/style.css
@@ -1 +1,33 @@
 @import url("https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css");
+
+#container {
+  max-width: 800px;
+  margin: auto;
+}
+
+#head {
+  padding-top: 20px;
+  padding-bottom: 20px;
+  text-align: center;
+  font-size: 2em;
+}
+
+#subhead {
+  text-align: right;
+  font-size: 1.2em;
+}
+
+#body {
+  font-size: 1.0em;
+}
+
+#info {
+  font-size: 0.9em;
+  padding-top: 10px;
+}
+
+#foot {
+  padding-top: 20px;
+  text-align: center;
+  font-size: 0.8em;
+}
diff --git a/assets/tmpl/index.html b/assets/tmpl/index.html
index fdd91ca..e702d08 100644
--- a/assets/tmpl/index.html
+++ b/assets/tmpl/index.html
@@ -3,11 +3,62 @@
 <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+  <meta name="application-name" content="getwtxt">
   <link rel="stylesheet" type="text/css" href="/css">
-  <title>{{.Title}} - twtxt Registry</title>
+  <title>{{.Name}} - twtxt Registry</title>
 </head>
 <body>
   <div id="container">
+    <div id="head">
+      <h2>{{.Name}}</h2>
+    </div>
+    <div id="subhead">
+      twtxt registry
+    </div>
+    <div id="body">
+      <p>{{.Desc}}</p>
+      <p>API base URL:</p>
+      <pre><code>/api</code></pre>
+          <p>Formats available:</p>
+        <pre><code>/api/plain</code></pre>
+      <p>Endpoints:</p>
+<pre><code>/api/plain/users
+/api/plain/mentions
+/api/plain/tweets
+/api/plain/tags</code></pre>
+  <p>Query by user:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/users?q=foo'
+foo               https://example.com/twtxt.txt     2019-05-09T08:42:23.000Z
+foobar            https://example2.com/twtxt.txt    2019-03-14T19:23:00.000Z
+foo_barrington    https://example3.com/twtxt.txt    2019-05-01T15:59:39.000Z</code></pre>
+          <p>Query by tweet content:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/tweets?q=getwtxt'
+foo_barrington    https://example3.com/twtxt.txt    2019-04-30T06:00:09.000Z    I just built getwtxt, time to set it up!</code></pre>
+          <p>Query by mention:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/mentions?url=https://foobarrington.co.uk/twtxt.txt'
+foo    https://example.com/twtxt.txt    2019-02-26T11:06:44.000Z    @<foo_barrington https://example3.com/twtxt.txt> Hey!! Are you still working on that project?</code></pre>
+          <p>Query by tag:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/tags/programming'
+foo    https://example.com/twtxt.txt    2019-03-01T09:31:02.000Z    I love #programming!</code></pre>
+          <p>Get latest 20 tweets:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/tweets'
+foobar    https://example2.com/twtxt.txt    2019-05-13T12:46:20.000Z    It's been a busy day at work!
+...</code></pre>
+          <p>Get all users:</p>
+        <pre><code>$ curl 'https://getwtxt.example.com/api/plain/users'
+foo_barrington    https://example3.com/twtxt.txt    2018-11-21T18:31:00.000Z
+...</code></pre>
+          <p>Add new user:</p>
+        <pre><code>$ curl -X POST 'https://getwtxt.example.com/api/plain/users?url=https://example3.com/twtxt.txt&nickname=foo_barrington'
+OK</code></pre>
+    </div>
+    <div id="info">
+    Instance Owner: {{.Owner}}<br />
+    Mail: {{.Mail}}<br />
+    </div>
+    <div id="foot">
+      powered by <a href="https://github.com/gbmor/getwtxt">getwtxt</a>
+    </div>
   </div>
 </body>
 </html>
diff --git a/getwtxt.json b/getwtxt.json
index 66c725e..60afa6a 100644
--- a/getwtxt.json
+++ b/getwtxt.json
@@ -5,7 +5,8 @@
   "instance": {
     "name": "getwtxt",
     "url": "https://twtxt.example.com",
-    "owner": "gbmor",
-    "mail": "ben@gbmor.dev"
+    "owner": "foo barrington",
+    "mail": "foo@barrington.ext",
+    "description": "This is the twtxt registry for the tildeverse network of public unix servers."
   }
 }
diff --git a/handlers.go b/handlers.go
index 3b23761..961ac4f 100644
--- a/handlers.go
+++ b/handlers.go
@@ -15,9 +15,11 @@ import (
 // handles "/"
 func indexHandler(w http.ResponseWriter, _ *http.Request) {
 	w.Header().Set("Content-Type", htmlutf8)
-	n, err := w.Write([]byte("getwtxt v" + getwtxt))
-	if err != nil || n == 0 {
-		log.Printf("Error writing to HTTP stream: %v bytes,  %v\n", n, err)
+	err := tmpls.ExecuteTemplate(w, "index.html", confObj.Instance)
+	if err != nil {
+		log.Printf("Error writing to HTTP stream: %v\n", err)
+		http.Error(w, err.Error(), http.StatusInternalServerError)
+		return
 	}
 
 }
diff --git a/init.go b/init.go
index f871a72..ee76f01 100644
--- a/init.go
+++ b/init.go
@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"html/template"
 	"log"
 	"os"
 	"os/signal"
@@ -24,11 +25,15 @@ var confObj = &configuration{}
 // signals to close the log file
 var closelog = make(chan bool, 1)
 
+// templates
+var tmpls *template.Template
+
 func init() {
 	checkFlags()
 	titleScreen()
 	initConfig()
 	initLogging()
+	tmpls = initTemplates()
 	watchForInterrupt()
 }
 
@@ -69,15 +74,17 @@ func initConfig() {
 
 	viper.SetDefault("port", 9001)
 	viper.SetDefault("logfile", "getwtxt.log")
-	viper.SetDefault("twtxtfile", "/var/twtxt/twtxt.txt")
+	viper.SetDefault("stdoutLogging", false)
 
 	confObj.port = viper.GetInt("port")
 	confObj.logfile = viper.GetString("logfile")
 	confObj.stdoutLogging = viper.GetBool("stdoutLogging")
-	confObj.instance.name = viper.GetString("instance.name")
-	confObj.instance.url = viper.GetString("instance.url")
-	confObj.instance.owner = viper.GetString("instance.owner")
-	confObj.instance.mail = viper.GetString("instance.mail")
+	confObj.version = getwtxt
+	confObj.Instance.Name = viper.GetString("instance.name")
+	confObj.Instance.URL = viper.GetString("instance.url")
+	confObj.Instance.Owner = viper.GetString("instance.owner")
+	confObj.Instance.Mail = viper.GetString("instance.mail")
+	confObj.Instance.Desc = viper.GetString("instance.description")
 }
 
 func initLogging() {
@@ -121,15 +128,21 @@ func rebindConfig() {
 	confObj.port = viper.GetInt("port")
 	confObj.logfile = viper.GetString("logfile")
 	confObj.stdoutLogging = viper.GetBool("stdoutLogging")
-	confObj.instance.name = viper.GetString("instance.name")
-	confObj.instance.url = viper.GetString("instance.url")
-	confObj.instance.owner = viper.GetString("instance.owner")
-	confObj.instance.mail = viper.GetString("instance.mail")
+	confObj.Instance.Name = viper.GetString("instance.name")
+	confObj.Instance.URL = viper.GetString("instance.url")
+	confObj.Instance.Owner = viper.GetString("instance.owner")
+	confObj.Instance.Mail = viper.GetString("instance.mail")
+	confObj.Instance.Desc = viper.GetString("instance.description")
 
 	// reinitialize logging
 	initLogging()
 }
 
+// Parse the HTML templates
+func initTemplates() *template.Template {
+	return template.Must(template.ParseFiles("assets/tmpl/index.html"))
+}
+
 // Watch for SIGINT aka ^C
 // Close the log file then exit
 func watchForInterrupt() {
diff --git a/types.go b/types.go
index c7d1c50..8a707bd 100644
--- a/types.go
+++ b/types.go
@@ -10,13 +10,15 @@ type configuration struct {
 	port          int
 	logfile       string
 	stdoutLogging bool
-	instance
+	version       string
+	Instance
 }
 
-// refers to this specific instance of getwtxt
-type instance struct {
-	name  string
-	url   string
-	owner string
-	mail  string
+// Instance refers to this specific instance of getwtxt
+type Instance struct {
+	Name  string
+	URL   string
+	Owner string
+	Mail  string
+	Desc  string
 }