Skip to content
Draft
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
5 changes: 3 additions & 2 deletions context/context-legacy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !go1.7
// +build !go1.7

package context
Expand All @@ -8,11 +9,11 @@ import (
"github.com/gorilla/context"
)

func Get(r *http.Request, key interface{}) interface{} {
func Get(r *http.Request, key any) any {
return context.Get(r, key)
}

func Set(r *http.Request, key, val interface{}) *http.Request {
func Set(r *http.Request, key, val any) *http.Request {
if val == nil {
return r
}
Expand Down
5 changes: 3 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.7
// +build go1.7

package context
Expand All @@ -9,12 +10,12 @@ import (
)

// Get retrieves a value from the request context
func Get(r *http.Request, key interface{}) interface{} {
func Get(r *http.Request, key any) any {
return r.Context().Value(key)
}

// Set stores a value on the request context
func Set(r *http.Request, key, val interface{}) *http.Request {
func Set(r *http.Request, key, val any) *http.Request {
if val == nil {
return r
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/api/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// JSONResponse attempts to set the status code, c, and marshal the given interface, d, into a response that
// is written to the given ResponseWriter.
func JSONResponse(w http.ResponseWriter, d interface{}, c int) {
func JSONResponse(w http.ResponseWriter, d any, c int) {
dj, err := json.MarshalIndent(d, "", " ")
if err != nil {
http.Error(w, "Error creating JSON response", http.StatusInternalServerError)
Expand Down
6 changes: 3 additions & 3 deletions controllers/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (as *AdminServer) registerRoutes() {

type templateParams struct {
Title string
Flashes []interface{}
Flashes []any
User models.User
Token string
Version string
Expand Down Expand Up @@ -311,7 +311,7 @@ func (as *AdminServer) handleInvalidLogin(w http.ResponseWriter, r *http.Request
params := struct {
User models.User
Title string
Flashes []interface{}
Flashes []any
Token string
}{Title: "Login", Token: csrf.Token(r)}
params.Flashes = session.Flashes()
Expand Down Expand Up @@ -357,7 +357,7 @@ func (as *AdminServer) Login(w http.ResponseWriter, r *http.Request) {
params := struct {
User models.User
Title string
Flashes []interface{}
Flashes []any
Token string
}{Title: "Login", Token: csrf.Token(r)}
session := ctx.Get(r, "session").(*sessions.Session)
Expand Down
2 changes: 1 addition & 1 deletion imap/imap.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Client interface {
Login(username, password string) (cmd *imap.Command, err error)
Logout(timeout time.Duration) (cmd *imap.Command, err error)
Select(name string, readOnly bool) (mbox *imap.MailboxStatus, err error)
Store(seq *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) (err error)
Store(seq *imap.SeqSet, item imap.StoreItem, value any, ch chan *imap.Message) (err error)
Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) (err error)
}

Expand Down
20 changes: 10 additions & 10 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,52 @@ func Setup(config *Config) error {
}

// Debug logs a debug message
func Debug(args ...interface{}) {
func Debug(args ...any) {
Logger.Debug(args...)
}

// Debugf logs a formatted debug messsage
func Debugf(format string, args ...interface{}) {
func Debugf(format string, args ...any) {
Logger.Debugf(format, args...)
}

// Info logs an informational message
func Info(args ...interface{}) {
func Info(args ...any) {
Logger.Info(args...)
}

// Infof logs a formatted informational message
func Infof(format string, args ...interface{}) {
func Infof(format string, args ...any) {
Logger.Infof(format, args...)
}

// Error logs an error message
func Error(args ...interface{}) {
func Error(args ...any) {
Logger.Error(args...)
}

// Errorf logs a formatted error message
func Errorf(format string, args ...interface{}) {
func Errorf(format string, args ...any) {
Logger.Errorf(format, args...)
}

// Warn logs a warning message
func Warn(args ...interface{}) {
func Warn(args ...any) {
Logger.Warn(args...)
}

// Warnf logs a formatted warning message
func Warnf(format string, args ...interface{}) {
func Warnf(format string, args ...any) {
Logger.Warnf(format, args...)
}

// Fatal logs a fatal error message
func Fatal(args ...interface{}) {
func Fatal(args ...any) {
Logger.Fatal(args...)
}

// Fatalf logs a formatted fatal error message
func Fatalf(format string, args ...interface{}) {
func Fatalf(format string, args ...any) {
Logger.Fatalf(format, args...)
}

Expand Down
2 changes: 1 addition & 1 deletion models/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func insertTargetIntoGroup(tx *gorm.DB, t Target, gid int64) error {

// UpdateTarget updates the given target information in the database.
func UpdateTarget(tx *gorm.DB, target Target) error {
targetInfo := map[string]interface{}{
targetInfo := map[string]any{
"first_name": target.FirstName,
"last_name": target.LastName,
"position": target.Position,
Expand Down
6 changes: 3 additions & 3 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ type Flash struct {

// Response contains the attributes found in an API response
type Response struct {
Message string `json:"message"`
Success bool `json:"success"`
Data interface{} `json:"data"`
Message string `json:"message"`
Success bool `json:"success"`
Data any `json:"data"`
}

// Copy of auth.GenerateSecureKey to prevent cyclic import with auth library
Expand Down
2 changes: 1 addition & 1 deletion models/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Result struct {
BaseRecipient
}

func (r *Result) createEvent(status string, details interface{}) (*Event, error) {
func (r *Result) createEvent(status string, details any) (*Event, error) {
e := &Event{Email: r.Email, Message: status}
if details != nil {
dj, err := json.Marshal(details)
Expand Down
2 changes: 1 addition & 1 deletion models/template_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewPhishingTemplateContext(ctx TemplateContext, r BaseRecipient, rid string

// ExecuteTemplate creates a templated string based on the provided
// template body and data.
func ExecuteTemplate(text string, data interface{}) (string, error) {
func ExecuteTemplate(text string, data any) (string, error) {
buff := bytes.Buffer{}
tmpl, err := template.New("template").Parse(text)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (

// Sender represents a type which can send webhooks to an EndPoint
type Sender interface {
Send(endPoint EndPoint, data interface{}) error
Send(endPoint EndPoint, data any) error
}

type defaultSender struct {
Expand Down Expand Up @@ -64,12 +64,12 @@ type EndPoint struct {
}

// Send sends data to a single EndPoint
func Send(endPoint EndPoint, data interface{}) error {
func Send(endPoint EndPoint, data any) error {
return senderInstance.Send(endPoint, data)
}

// SendAll sends data to multiple EndPoints
func SendAll(endPoints []EndPoint, data interface{}) {
func SendAll(endPoints []EndPoint, data any) {
for _, e := range endPoints {
go func(e EndPoint) {
senderInstance.Send(e, data)
Expand All @@ -78,7 +78,7 @@ func SendAll(endPoints []EndPoint, data interface{}) {
}

// Send contains the implementation of sending webhook to an EndPoint
func (ds defaultSender) Send(endPoint EndPoint, data interface{}) error {
func (ds defaultSender) Send(endPoint EndPoint, data any) error {
jsonData, err := json.Marshal(data)
if err != nil {
log.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newMockSender() *mockSender {
return ms
}

func (ms mockSender) Send(endPoint EndPoint, data interface{}) error {
func (ms mockSender) Send(endPoint EndPoint, data any) error {
log.Println("[test] mocked 'Send' function")
return nil
}
Expand All @@ -44,7 +44,7 @@ func TestSendMocked(t *testing.T) {
func TestSendReal(t *testing.T) {
expectedSig := "004b36ca3fcbc01a08b17bf5d4a7e1aa0b10e14f55f3f8bd9acac0c7e8d2635d"
secret := "secret456"
data := map[string]interface{}{
data := map[string]any{
"key1": "val1",
"key2": "val2",
"key3": "val3",
Expand All @@ -71,7 +71,7 @@ func TestSendReal(t *testing.T) {
t.Fatalf("error reading JSON body from webhook request: %v", err)
}

var payload map[string]interface{}
var payload map[string]any
err = json.Unmarshal(body, &payload)
if err != nil {
t.Fatalf("error unmarshaling webhook payload: %v", err)
Expand Down