finish filling in structs
parent
3f1b6330c4
commit
453b77521c
54
main.go
54
main.go
|
@ -1,11 +1,3 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
// townstats returns information about tilde.town in the tilde data protcol format
|
// townstats returns information about tilde.town in the tilde data protcol format
|
||||||
// It was originally a Python script written by Michael F. Lamb <https://datagrok.org>
|
// It was originally a Python script written by Michael F. Lamb <https://datagrok.org>
|
||||||
// License: GPLv3+
|
// License: GPLv3+
|
||||||
|
@ -15,6 +7,14 @@ import (
|
||||||
|
|
||||||
// Usage: stats > /var/www/html/tilde.json
|
// Usage: stats > /var/www/html/tilde.json
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
// TODO read ENV var for additional system users but hard code the ones we know about
|
// TODO read ENV var for additional system users but hard code the ones we know about
|
||||||
|
|
||||||
const default_html_filename = "/etc/skel/public_html/index.html"
|
const default_html_filename = "/etc/skel/public_html/index.html"
|
||||||
|
@ -24,7 +24,9 @@ non-commercial, donation supported, and committed to rejecting false
|
||||||
technological progress in favor of empathy and sustainable computing.`
|
technological progress in favor of empathy and sustainable computing.`
|
||||||
|
|
||||||
type NewsEntry struct {
|
type NewsEntry struct {
|
||||||
// TODO
|
Title string `json:"title"` // Title of entry
|
||||||
|
Pubdate string `json:"pubdate"` // Human readable date
|
||||||
|
Content string `json:"content"` // HTML of entry
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -49,10 +51,15 @@ type TildeData struct {
|
||||||
// Town Additions
|
// Town Additions
|
||||||
LiveUserCount int `json:"live_user_count"` // Users who have changed their index.html
|
LiveUserCount int `json:"live_user_count"` // Users who have changed their index.html
|
||||||
ActiveUserCount int `json:"active_user_count"` // Users with an active login
|
ActiveUserCount int `json:"active_user_count"` // Users with an active login
|
||||||
GeneratedAt int `json:"generated_at"` // When this was generated in '%Y-%m-%d %H:%M:%S' format
|
GeneratedAt string `json:"generated_at"` // When this was generated in '%Y-%m-%d %H:%M:%S' format
|
||||||
GenaratedAtsec int `json:"generated_at_msec"` // When this was generated in seconds since epoch
|
GeneratedAtMsec int `json:"generated_at_msec"` // When this was generated in milliseconds since epoch
|
||||||
Uptime string `json:"uptime"` // output of `uptime -p`
|
Uptime string `json:"uptime"` // output of `uptime -p`
|
||||||
News []NewsEntry
|
News []NewsEntry // Collection of town news entries
|
||||||
|
}
|
||||||
|
|
||||||
|
func news() []NewsEntry {
|
||||||
|
// TODO
|
||||||
|
return []NewsEntry{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func userCount() int {
|
func userCount() int {
|
||||||
|
@ -65,6 +72,21 @@ func users() []User {
|
||||||
return []User{}
|
return []User{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func liveUserCount() int {
|
||||||
|
// TODO
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func activeUserCount() int {
|
||||||
|
// TODO
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func uptime() string {
|
||||||
|
// TODO
|
||||||
|
return "TODO"
|
||||||
|
}
|
||||||
|
|
||||||
func tdp() TildeData {
|
func tdp() TildeData {
|
||||||
return TildeData{
|
return TildeData{
|
||||||
Name: "tilde.town",
|
Name: "tilde.town",
|
||||||
|
@ -75,15 +97,19 @@ func tdp() TildeData {
|
||||||
Description: description,
|
Description: description,
|
||||||
UserCount: userCount(),
|
UserCount: userCount(),
|
||||||
Users: users(),
|
Users: users(),
|
||||||
|
LiveUserCount: liveUserCount(),
|
||||||
|
ActiveUserCount: activeUserCount(),
|
||||||
|
Uptime: uptime(),
|
||||||
|
News: news(),
|
||||||
|
GeneratedAt: "TODO",
|
||||||
|
GeneratedAtMsec: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
data, err := json.Marshal(tdp())
|
data, err := json.Marshal(tdp())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to marshal JSON: %s", err)
|
log.Fatalf("Failed to marshal JSON: %s", err)
|
||||||
}
|
}
|
||||||
fmt.Printf("%s\n", data)
|
fmt.Printf("%s\n", data)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue