Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golint #255

Merged
merged 1 commit into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions cmd/gotosocial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions internal/cache/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
uris map[string]string // map of status URIs -> IDs
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(),
Expand Down
2 changes: 2 additions & 0 deletions internal/db/bundb/bundb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
3 changes: 2 additions & 1 deletion internal/db/bundb/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
17 changes: 8 additions & 9 deletions internal/router/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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))
Expand Down
7 changes: 5 additions & 2 deletions internal/web/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/web/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down