diff --git a/cmd/gotosocial/main.go b/cmd/gotosocial/main.go index a5c6ef56a..80cca5b23 100644 --- a/cmd/gotosocial/main.go +++ b/cmd/gotosocial/main.go @@ -16,30 +16,6 @@ along with this program. If not, see . */ -// 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 index f6fe45d99..5ea528055 100644 --- a/internal/cache/status.go +++ b/internal/cache/status.go @@ -7,7 +7,7 @@ "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 index e1879f247..e6ebe5d88 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -45,6 +45,8 @@ "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 index abaebcebd..aeb1b5db0 100644 --- a/internal/db/bundb/conn.go +++ b/internal/db/bundb/conn.go @@ -10,7 +10,7 @@ "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 index 2beee63c0..4f387daed 100644 --- 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(``, icon.label, icon.faIcon)) diff --git a/internal/web/base.go b/internal/web/base.go index 2759c3f9e..7be834a46 100644 --- a/internal/web/base.go +++ b/internal/web/base.go @@ -32,12 +32,14 @@ "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 index 247bf0dc8..b9a1a10fa 100644 --- a/internal/web/fileserver.go +++ b/internal/web/fileserver.go @@ -23,13 +23,13 @@ "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