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
|
||||
// It was originally a Python script written by Michael F. Lamb <https://datagrok.org>
|
||||
// License: GPLv3+
|
||||
|
@ -15,6 +7,14 @@ import (
|
|||
|
||||
// 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
|
||||
|
||||
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.`
|
||||
|
||||
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 {
|
||||
|
@ -49,10 +51,15 @@ type TildeData struct {
|
|||
// Town Additions
|
||||
LiveUserCount int `json:"live_user_count"` // Users who have changed their index.html
|
||||
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
|
||||
GenaratedAtsec int `json:"generated_at_msec"` // When this was generated in seconds since epoch
|
||||
GeneratedAt string `json:"generated_at"` // When this was generated in '%Y-%m-%d %H:%M:%S' format
|
||||
GeneratedAtMsec int `json:"generated_at_msec"` // When this was generated in milliseconds since epoch
|
||||
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 {
|
||||
|
@ -65,6 +72,21 @@ func users() []User {
|
|||
return []User{}
|
||||
}
|
||||
|
||||
func liveUserCount() int {
|
||||
// TODO
|
||||
return 0
|
||||
}
|
||||
|
||||
func activeUserCount() int {
|
||||
// TODO
|
||||
return 0
|
||||
}
|
||||
|
||||
func uptime() string {
|
||||
// TODO
|
||||
return "TODO"
|
||||
}
|
||||
|
||||
func tdp() TildeData {
|
||||
return TildeData{
|
||||
Name: "tilde.town",
|
||||
|
@ -75,15 +97,19 @@ func tdp() TildeData {
|
|||
Description: description,
|
||||
UserCount: userCount(),
|
||||
Users: users(),
|
||||
LiveUserCount: liveUserCount(),
|
||||
ActiveUserCount: activeUserCount(),
|
||||
Uptime: uptime(),
|
||||
News: news(),
|
||||
GeneratedAt: "TODO",
|
||||
GeneratedAtMsec: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
data, err := json.Marshal(tdp())
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to marshal JSON: %s", err)
|
||||
}
|
||||
fmt.Printf("%s\n", data)
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue