utils

package
v0.0.0-...-f6108e4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorJSON

func ErrorJSON(w http.ResponseWriter, err error, status ...int) error

func ReadJSON

func ReadJSON(w http.ResponseWriter, r *http.Request, data any) error

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any, headers ...http.Header) error

Types

type JsonResponse

type JsonResponse struct {
	Error   bool   `json:"error"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type LogHandler

type LogHandler struct {
	// contains filtered or unexported fields
}

func StructuredLogHandler

func StructuredLogHandler(writer *os.File, appName string) *LogHandler

StructuredLogHandler returns a new LogHandler

func (*LogHandler) Enabled

func (h *LogHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled method to indicate which log levels are enabled

func (*LogHandler) Handle

func (h *LogHandler) Handle(ctx context.Context, record slog.Record) error

Handle implements the Handle method of the slog.Handler interface

func (*LogHandler) WithAttrs

func (h *LogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements the WithAttrs method of the slog.Handler interface

func (*LogHandler) WithGroup

func (h *LogHandler) WithGroup(name string) slog.Handler

WithGroup implements the WithGroup method of the slog.Handler interface

type User

type User struct {
	Id        string    `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Password  string    `json:"password,omitempty"`
	Roles     []string  `json:"roles"`
	Xp        int32     `json:"xp"`
	IsBanned  bool      `json:"is_banned"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func DecodeMultipleProtoUsers

func DecodeMultipleProtoUsers(users []*user.User) []User

func DecodeProtoUser

func DecodeProtoUser(u *user.User) User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL