gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 231075f28df55bfb622f54859f858528445cae0c
parent 36a09dd0df06e1b6f64347ed3d3c2c8ca963fc73
Author: tobi <31960611+tsmethurst@users.noreply.github.com>
Date:   Thu, 30 Sep 2021 11:16:23 +0200

Golint (#255)


Diffstat:
Mcmd/gotosocial/main.go | 24------------------------
Minternal/cache/status.go | 4++--
Minternal/db/bundb/bundb.go | 2++
Minternal/db/bundb/conn.go | 3++-
Minternal/router/template.go | 17++++++++---------
Minternal/web/base.go | 7+++++--
Minternal/web/fileserver.go | 4++--
7 files changed, 21 insertions(+), 40 deletions(-)

diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go @@ -16,30 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -// Package classification awesome. -// -// Documentation of our awesome AaaaaaaaaaPI. -// -// Schemes: http -// BasePath: / -// Version: 1.0.0 -// Host: some-url.com -// -// Consumes: -// - application/json -// -// Produces: -// - application/json -// -// Security: -// - basic -// -// SecurityDefinitions: -// basic: -// type: basic -// -// swagger:meta - package main import ( diff --git a/internal/cache/status.go b/internal/cache/status.go @@ -7,7 +7,7 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" ) -// statusCache is a wrapper around ttlcache.Cache to provide URL and URI lookups for gtsmodel.Status +// StatusCache is a wrapper around ttlcache.Cache to provide URL and URI lookups for gtsmodel.Status type StatusCache struct { cache *ttlcache.Cache // map of IDs -> cached statuses urls map[string]string // map of status URLs -> IDs @@ -15,7 +15,7 @@ type StatusCache struct { mutex sync.Mutex } -// newStatusCache returns a new instantiated statusCache object +// NewStatusCache returns a new instantiated statusCache object func NewStatusCache() *StatusCache { c := StatusCache{ cache: ttlcache.NewCache(), diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go @@ -45,6 +45,8 @@ import ( "github.com/uptrace/bun/dialect/pgdialect" "github.com/uptrace/bun/dialect/sqlitedialect" "github.com/uptrace/bun/migrate" + + // blank import for the sqlite driver for bun _ "modernc.org/sqlite" ) diff --git a/internal/db/bundb/conn.go b/internal/db/bundb/conn.go @@ -10,7 +10,7 @@ import ( "github.com/uptrace/bun/dialect" ) -// dbConn wrapps a bun.DB conn to provide SQL-type specific additional functionality +// DBConn wrapps a bun.DB conn to provide SQL-type specific additional functionality type DBConn struct { // TODO: move *Config here, no need to be in each struct type @@ -37,6 +37,7 @@ func WrapDBConn(dbConn *bun.DB, log *logrus.Logger) *DBConn { } } +// RunInTx wraps execution of the supplied transaction function. func (conn *DBConn) RunInTx(ctx context.Context, fn func(bun.Tx) error) db.Error { // Acquire a new transaction tx, err := conn.BeginTx(ctx, nil) diff --git a/internal/router/template.go b/internal/router/template.go @@ -46,9 +46,8 @@ func loadTemplates(cfg *config.Config, engine *gin.Engine) error { func oddOrEven(n int) string { if n%2 == 0 { return "even" - } else { - return "odd" } + return "odd" } func noescape(str string) template.HTML { @@ -60,24 +59,24 @@ func timestamp(stamp string) string { return t.Format("January 2, 2006, 15:04:05") } -type IconWithLabel struct { +type iconWithLabel struct { faIcon string label string } func visibilityIcon(visibility model.Visibility) template.HTML { - var icon IconWithLabel + var icon iconWithLabel if visibility == model.VisibilityPublic { - icon = IconWithLabel{"globe", "public"} + icon = iconWithLabel{"globe", "public"} } else if visibility == model.VisibilityUnlisted { - icon = IconWithLabel{"unlock", "unlisted"} + icon = iconWithLabel{"unlock", "unlisted"} } else if visibility == model.VisibilityPrivate { - icon = IconWithLabel{"lock", "private"} + icon = iconWithLabel{"lock", "private"} } else if visibility == model.VisibilityMutualsOnly { - icon = IconWithLabel{"handshake-o", "mutuals only"} + icon = iconWithLabel{"handshake-o", "mutuals only"} } else if visibility == model.VisibilityDirect { - icon = IconWithLabel{"envelope", "direct"} + icon = iconWithLabel{"envelope", "direct"} } return template.HTML(fmt.Sprintf(`<i aria-label="Visiblity: %v" class="fa fa-%v"></i>`, icon.label, icon.faIcon)) diff --git a/internal/web/base.go b/internal/web/base.go @@ -32,12 +32,14 @@ import ( "github.com/superseriousbusiness/gotosocial/internal/router" ) +// Module implements the api.ClientModule interface for web pages. type Module struct { config *config.Config processor processing.Processor log *logrus.Logger } +// New returns a new api.ClientModule for web pages. func New(config *config.Config, processor processing.Processor, log *logrus.Logger) api.ClientModule { return &Module{ config: config, @@ -62,6 +64,7 @@ func (m *Module) baseHandler(c *gin.Context) { }) } +// NotFoundHandler serves a 404 html page instead of a blank 404 error. func (m *Module) NotFoundHandler(c *gin.Context) { l := m.log.WithField("func", "404") l.Trace("serving 404 html") @@ -87,11 +90,11 @@ func (m *Module) Route(s router.Router) error { return fmt.Errorf("error getting current working directory: %s", err) } assetPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir) - s.AttachStaticFS("/assets", FileSystem{http.Dir(assetPath)}) + s.AttachStaticFS("/assets", fileSystem{http.Dir(assetPath)}) // Admin panel route, if it exists adminPath := filepath.Join(cwd, m.config.TemplateConfig.AssetBaseDir, "/admin") - s.AttachStaticFS("/admin", FileSystem{http.Dir(adminPath)}) + s.AttachStaticFS("/admin", fileSystem{http.Dir(adminPath)}) // serve front-page s.AttachHandler(http.MethodGet, "/", m.baseHandler) diff --git a/internal/web/fileserver.go b/internal/web/fileserver.go @@ -23,13 +23,13 @@ import ( "strings" ) -type FileSystem struct { +type fileSystem struct { fs http.FileSystem } // FileSystem server that only accepts directory listings when an index.html is available // from https://gist.github.com/hauxe/f2ea1901216177ccf9550a1b8bd59178 -func (fs FileSystem) Open(path string) (http.File, error) { +func (fs fileSystem) Open(path string) (http.File, error) { f, err := fs.fs.Open(path) if err != nil { return nil, err