dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 245251d3ae5c589b577a3b2e6ac6ef2d317892bc
parent a04a06b2163e1153b6d2068662fa5334783dfb4d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat,  3 Dec 2022 22:51:52 -0500

cleanup

Diffstat:
Mpkg/database/encryptedString.go | 2+-
Mpkg/pubsub/pubsub.go | 4++--
Mpkg/template/fn.go | 12++++++------
Mpkg/template/template.go | 4++--
Mpkg/template/templates.go | 4++--
Mpkg/utils/utils.go | 6+++---
Mpkg/web/handlers/api/v1/handlers.go | 4++--
7 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/pkg/database/encryptedString.go b/pkg/database/encryptedString.go @@ -11,7 +11,7 @@ import ( type EncryptedString string // Scan EncryptedString implements scanner interface -func (s *EncryptedString) Scan(val interface{}) error { +func (s *EncryptedString) Scan(val any) error { v, err := utils.DecryptAES(val.([]byte), []byte(config.Global.MasterKey())) *s = EncryptedString(v) if err != nil { diff --git a/pkg/pubsub/pubsub.go b/pkg/pubsub/pubsub.go @@ -124,7 +124,7 @@ func PublishString(topic string, msg string) { } // Publish a message to all subscribers of a topic -func Publish(topic string, msg interface{}) error { +func Publish(topic string, msg any) error { marshalled, err := json.Marshal(msg) if err != nil { return err @@ -134,6 +134,6 @@ func Publish(topic string, msg interface{}) error { } // Pub shortcut for publish which ignore the error -func Pub(topic string, msg interface{}) { +func Pub(topic string, msg any) { _ = Publish(topic, msg) } diff --git a/pkg/template/fn.go b/pkg/template/fn.go @@ -114,12 +114,12 @@ func int64bytes(val int64) string { return humanize.Bytes(uint64(val)) } -func toString(v interface{}) string { +func toString(v any) string { b, _ := json.Marshal(v) return string(b) } -func toI64(v interface{}) int64 { +func toI64(v any) int64 { if i, ok := v.(int64); ok { return i } @@ -179,7 +179,7 @@ func until(date time.Time) string { return humanize.Time(date) } -func notNil(v interface{}) interface{} { +func notNil(v any) any { if v == nil || (reflect.ValueOf(v).Kind() == reflect.Ptr && reflect.ValueOf(v).IsNil()) { return "" } @@ -190,7 +190,7 @@ func shortDurNs(ns uint64) string { return time.Duration(ns).String() } -func shortDur(v interface{}) string { +func shortDur(v any) string { return utils.ShortDur(v) } @@ -268,8 +268,8 @@ func trunc(nb int64, in string) string { return in } -func dict(vals ...interface{}) map[string]interface{} { - out := make(map[string]interface{}) +func dict(vals ...any) map[string]any { + out := make(map[string]any) for i := 0; i < len(vals); i += 2 { k := vals[i].(string) v := vals[i+1] diff --git a/pkg/template/template.go b/pkg/template/template.go @@ -107,12 +107,12 @@ func (t *Template) ParseFiles(filenames ...string) (*Template, error) { } // Execute is a proxy to the underlying template's Execute function -func (t *Template) Execute(w io.Writer, data interface{}) error { +func (t *Template) Execute(w io.Writer, data any) error { return t.Tmpl.Execute(w, data) } // ExecuteTemplate is a proxy to the underlying template's ExecuteTemplate function -func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error { +func (t *Template) ExecuteTemplate(wr io.Writer, name string, data any) error { return t.Tmpl.ExecuteTemplate(wr, name, data) } diff --git a/pkg/template/templates.go b/pkg/template/templates.go @@ -34,7 +34,7 @@ func NewTemplateBuilder(e *echo.Echo) *Templates { } // AddFn ... -func (t *Templates) AddFn(name string, fn interface{}) { +func (t *Templates) AddFn(name string, fn any) { t.funcMap[name] = fn } @@ -42,7 +42,7 @@ type templateDataStruct struct { Bundle *i18n.Bundle AcceptLanguage string Lang string - Data interface{} + Data any VERSION string SHA string VersionHTML template.HTML diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go @@ -59,7 +59,7 @@ const ( ) // H is a hashmap -type H map[string]interface{} +type H map[string]any // SGo stands for Safe Go or Shit Go depending how you feel about goroutine panic handling // Basically just a wrapper around the built-in keyword "go" with crash recovery @@ -91,7 +91,7 @@ func EnsureRangeDur(min, max time.Duration) (time.Duration, time.Duration) { return min, max } -func castStr(v interface{}) string { +func castStr(v any) string { if s, ok := v.(string); ok { return s } @@ -275,7 +275,7 @@ func BacktoIP4(ipInt int64) string { } // ShortDur ... -func ShortDur(v interface{}) string { +func ShortDur(v any) string { if d, ok := v.(time.Duration); ok { d = d.Round(time.Second) s := d.String() diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -399,7 +399,7 @@ func ChatInboxDeleteAllMessageHandler(c echo.Context) error { func GetCaptchaHandler(c echo.Context) error { //authUser := c.Get("authUser").(*database.User) captchaID, captchaImg := mycaptcha.New() - return c.JSON(http.StatusOK, map[string]interface{}{"ID": captchaID, "img": captchaImg}) + return c.JSON(http.StatusOK, map[string]any{"ID": captchaID, "img": captchaImg}) } func CaptchaSolverHandler(c echo.Context) error { @@ -418,7 +418,7 @@ func CaptchaSolverHandler(c echo.Context) error { if err := database.DB.Create(&captchaReq).Error; err != nil { logrus.Error(err.Error()) } - return c.JSON(http.StatusOK, map[string]interface{}{"answer": answer}) + return c.JSON(http.StatusOK, map[string]any{"answer": answer}) } func RoomNotifierHandler(c echo.Context) error {