From 9d7659948ddf6dea57513df37d4fd2d0416af7bf Mon Sep 17 00:00:00 2001
From: f0x
Date: Mon, 21 Jun 2021 18:58:32 +0200
Subject: [PATCH] fix package, adapt to proper Route structure
---
go.mod | 1 +
go.sum | 4 ++
internal/cliactions/server/server.go | 4 +-
internal/web/base.go | 61 +++++++++++++++++++---------
web/template/footer.tmpl | 6 +--
web/template/header.tmpl | 4 +-
web/template/index.tmpl | 7 +++-
7 files changed, 60 insertions(+), 27 deletions(-)
diff --git a/go.mod b/go.mod
index aec00d3..dd778c1 100644
--- a/go.mod
+++ b/go.mod
@@ -15,6 +15,7 @@ require (
github.com/dsoprea/go-utility v0.0.0-20200717064901-2fccff4aa15e // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/sessions v0.0.3
+ github.com/gin-contrib/static v0.0.1 // indirect
github.com/gin-gonic/gin v1.7.2
github.com/go-errors/errors v1.4.0 // indirect
github.com/go-fed/activity v1.0.1-0.20210426194615-e0de0863dcc1
diff --git a/go.sum b/go.sum
index 37dadf6..7de5381 100644
--- a/go.sum
+++ b/go.sum
@@ -66,7 +66,10 @@ github.com/gin-contrib/sessions v0.0.3 h1:PoBXki+44XdJdlgDqDrY5nDVe3Wk7wDV/UCOuL
github.com/gin-contrib/sessions v0.0.3/go.mod h1:8C/J6cad3Il1mWYYgtw0w+hqasmpvy25mPkXdOgeB9I=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
+github.com/gin-contrib/static v0.0.1 h1:JVxuvHPuUfkoul12N7dtQw7KRn/pSMq7Ue1Va9Swm1U=
+github.com/gin-contrib/static v0.0.1/go.mod h1:CSxeF+wep05e0kCOsqWdAWbSszmc31zTIbD8TvWl7Hs=
github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do=
+github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gin-gonic/gin v1.7.2 h1:Tg03T9yM2xa8j6I3Z3oqLaQRSmKvxPd6g/2HJ6zICFA=
github.com/gin-gonic/gin v1.7.2/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
@@ -95,6 +98,7 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
+github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-playground/validator/v10 v10.6.1 h1:W6TRDXt4WcWp4c4nf/G+6BkGdhiIo0k417gfr+V6u4I=
github.com/go-playground/validator/v10 v10.6.1/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk=
diff --git a/internal/cliactions/server/server.go b/internal/cliactions/server/server.go
index a06a52b..0ab8e46 100644
--- a/internal/cliactions/server/server.go
+++ b/internal/cliactions/server/server.go
@@ -43,7 +43,7 @@ import (
timelineprocessing "github.com/superseriousbusiness/gotosocial/internal/timeline"
"github.com/superseriousbusiness/gotosocial/internal/transport"
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
- "github.com/superseriousbusiness/gotosocial/internal/web/base"
+ "github.com/superseriousbusiness/gotosocial/internal/web"
)
var models []interface{} = []interface{}{
@@ -123,7 +123,7 @@ var Start cliactions.GTSAction = func(ctx context.Context, c *config.Config, log
appsModule := app.New(c, processor, log)
followRequestsModule := followrequest.New(c, processor, log)
webfingerModule := webfinger.New(c, processor, log)
- webBaseModule := webBase.new(c, log)
+ webBaseModule := web.New(c, processor, log)
usersModule := user.New(c, processor, log)
timelineModule := timeline.New(c, processor, log)
notificationModule := notification.New(c, processor, log)
diff --git a/internal/web/base.go b/internal/web/base.go
index eda3e92..e54150e 100644
--- a/internal/web/base.go
+++ b/internal/web/base.go
@@ -16,47 +16,70 @@
along with this program. If not, see .
*/
-package base
+package web
import (
+ "fmt"
"net/http"
+ "os"
+ "path/filepath"
+ "github.com/gin-contrib/static"
+ "github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
+ "github.com/superseriousbusiness/gotosocial/internal/api"
"github.com/superseriousbusiness/gotosocial/internal/config"
+ "github.com/superseriousbusiness/gotosocial/internal/processing"
"github.com/superseriousbusiness/gotosocial/internal/router"
)
type Module struct {
- config *config.Config
- log *logrus.Logger
+ config *config.Config
+ processor processing.Processor
+ log *logrus.Logger
}
-func New(config *config.Config, log *logrus.Logger) {
+func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule {
return &Module{
- config: config,
- log: log,
+ config: config,
+ log: log,
+ processor: processor,
}
}
+func (m *Module) baseHandler(c *gin.Context) {
+ l := m.log.WithField("func", "BaseGETHandler")
+ l.Trace("serving index html")
+
+ instance, err := m.processor.InstanceGet(m.config.Host)
+ if err != nil {
+ l.Debugf("error getting instance from processor: %s", err)
+ c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
+ return
+ }
+
+ // FIXME: fill in more variables?
+ c.HTML(http.StatusOK, "index.tmpl", gin.H{
+ "instance": instance,
+ "countUsers": 3,
+ "countStatuses": 42069,
+ "version": "1.0.0",
+ "adminUsername": "@admin",
+ })
+}
+
// Route satisfies the RESTAPIModule interface
func (m *Module) Route(s router.Router) error {
- l := m.log.WithField("func", "BaseGETHandler")
// serve static files from /assets
+ cwd, err := os.Getwd()
+ if err != nil {
+ return fmt.Errorf("error getting current working directory: %s", err)
+ }
assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir)
- s.Static("/assets", assetPath)
+ s.AttachMiddleware(static.Serve("/assets", static.LocalFile(assetPath, false)))
// serve front-page
- s.GET("/", func(c *gin.Context) {
- l.Trace("serving index html")
- // FIXME: actual variables
- c.HTML(http.StatusOK, "index.tmpl", gin.H{
- "instancename": "GoToSocial Test Instance",
- "countUsers": 3,
- "countStatuses": 42069,
- "version": "1.0.0",
- "adminUsername": "@admin",
- })
- })
+ s.AttachHandler(http.MethodGet, "/", m.baseHandler)
return nil
}
diff --git a/web/template/footer.tmpl b/web/template/footer.tmpl
index 9449a0e..19e9cdb 100644
--- a/web/template/footer.tmpl
+++ b/web/template/footer.tmpl
@@ -1,12 +1,12 @@
- {{.instancename}}
+ {{.instance.Title}}
\ No newline at end of file
diff --git a/web/template/index.tmpl b/web/template/index.tmpl
index 937d59b..8d431b8 100644
--- a/web/template/index.tmpl
+++ b/web/template/index.tmpl
@@ -3,7 +3,12 @@
- Home to {{.countUsers}} users who posted {{.countStatuses}} statuses.
+
+ Home to 3 users
+ who posted 42069 statuses,
+ federating with 9001 other instances.
This is the default landing page, you can edit it from ./web/template/index.tmpl