1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

update dependencies

This commit is contained in:
Gerasimos (Makis) Maropoulos
2025-08-15 23:29:20 +03:00
parent de4f462198
commit a8a3afea22
186 changed files with 694 additions and 689 deletions

View File

@@ -1,6 +1,6 @@
module myapp
go 1.24.3
go 1.25
require (
github.com/joho/godotenv v1.5.1

View File

@@ -56,7 +56,7 @@ type HTTPError struct {
Description string `json:"description"`
}
func newError(statusCode int, err error, format string, args ...interface{}) HTTPError {
func newError(statusCode int, err error, format string, args ...any) HTTPError {
if format == "" {
format = http.StatusText(statusCode)
}
@@ -92,7 +92,7 @@ func LogFailure(logger io.Writer, ctx iris.Context, err HTTPError) {
// Fail will send the status code, write the error's reason
// and return the HTTPError for further use, i.e logging, see `InternalServerError`.
func Fail(ctx iris.Context, statusCode int, err error, format string, args ...interface{}) HTTPError {
func Fail(ctx iris.Context, statusCode int, err error, format string, args ...any) HTTPError {
httpErr := newError(statusCode, err, format, args...)
httpErr.writeHeaders(ctx)
@@ -102,7 +102,7 @@ func Fail(ctx iris.Context, statusCode int, err error, format string, args ...in
// FailJSON will send to the client the error data as JSON.
// Useful for APIs.
func FailJSON(ctx iris.Context, statusCode int, err error, format string, args ...interface{}) HTTPError {
func FailJSON(ctx iris.Context, statusCode int, err error, format string, args ...any) HTTPError {
httpErr := newError(statusCode, err, format, args...)
httpErr.writeHeaders(ctx)
@@ -114,17 +114,17 @@ func FailJSON(ctx iris.Context, statusCode int, err error, format string, args .
// InternalServerError logs to the server's terminal
// and dispatches to the client the 500 Internal Server Error.
// Internal Server errors are critical, so we log them to the `os.Stderr`.
func InternalServerError(ctx iris.Context, err error, format string, args ...interface{}) {
func InternalServerError(ctx iris.Context, err error, format string, args ...any) {
LogFailure(os.Stderr, ctx, Fail(ctx, iris.StatusInternalServerError, err, format, args...))
}
// InternalServerErrorJSON acts exactly like `InternalServerError` but instead it sends the data as JSON.
// Useful for APIs.
func InternalServerErrorJSON(ctx iris.Context, err error, format string, args ...interface{}) {
func InternalServerErrorJSON(ctx iris.Context, err error, format string, args ...any) {
LogFailure(os.Stderr, ctx, FailJSON(ctx, iris.StatusInternalServerError, err, format, args...))
}
// UnauthorizedJSON sends JSON format of StatusUnauthorized(401) HTTPError value.
func UnauthorizedJSON(ctx iris.Context, err error, format string, args ...interface{}) HTTPError {
func UnauthorizedJSON(ctx iris.Context, err error, format string, args ...any) HTTPError {
return FailJSON(ctx, iris.StatusUnauthorized, err, format, args...)
}

View File

@@ -45,7 +45,7 @@ func (h *CategoryHandler) GetByID(ctx iris.Context) {
type (
List struct {
Data interface{} `json:"data"`
Data any `json:"data"`
Order string `json:"order"`
Next Range `json:"next,omitempty"`
Prev Range `json:"prev,omitempty"`
@@ -136,7 +136,7 @@ func (h *CategoryHandler) Update(ctx iris.Context) {
func (h *CategoryHandler) PartialUpdate(ctx iris.Context) {
id := ctx.Params().GetInt64Default("id", 0)
var attrs map[string]interface{}
var attrs map[string]any
if err := ctx.ReadJSON(&attrs); err != nil {
return
}

View File

@@ -8,7 +8,7 @@ import (
const debug = true
func debugf(format string, args ...interface{}) {
func debugf(format string, args ...any) {
if !debug {
return
}

View File

@@ -16,7 +16,7 @@ type Error struct {
Timestamp int64 `json:"timestamp"`
}
func newError(statusCode int, method, path, format string, args ...interface{}) Error {
func newError(statusCode int, method, path, format string, args ...any) Error {
msg := format
if len(args) > 0 {
// why we check for that? If the original error message came from our database

View File

@@ -127,7 +127,7 @@ func (h *ProductHandler) Update(ctx iris.Context) {
func (h *ProductHandler) PartialUpdate(ctx iris.Context) {
id := ctx.Params().GetInt64Default("id", 0)
var attrs map[string]interface{}
var attrs map[string]any
if err := ctx.ReadJSON(&attrs); err != nil {
return
}

View File

@@ -16,8 +16,8 @@ import (
// Service that cache will use to retrieve data.
type Service interface {
RecordInfo() sql.Record
GetByID(ctx context.Context, dest interface{}, id int64) error
List(ctx context.Context, dest interface{}, opts sql.ListOptions) error
GetByID(ctx context.Context, dest any, id int64) error
List(ctx context.Context, dest any, opts sql.ListOptions) error
}
// Cache is a simple structure which holds the groupcache and the database service, exposes
@@ -53,7 +53,7 @@ func (c *Cache) Get(ctx context.Context, key string, dest groupcache.Sink) error
return sql.ErrUnprocessable
}
var v interface{}
var v any
prefix := key[0:1]
key = key[1:]

View File

@@ -1,6 +1,6 @@
module myapp
go 1.24.3
go 1.25
require (
github.com/DATA-DOG/go-sqlmock v1.5.2

View File

@@ -69,6 +69,6 @@ var categoryUpdateSchema = map[string]reflect.Kind{
// PartialUpdate accepts a key-value map to
// update the record based on the given "id".
func (s *CategoryService) PartialUpdate(ctx context.Context, id int64, attrs map[string]interface{}) (int, error) {
func (s *CategoryService) PartialUpdate(ctx context.Context, id int64, attrs map[string]any) (int, error) {
return s.Service.PartialUpdate(ctx, id, categoryUpdateSchema, attrs)
}

View File

@@ -48,7 +48,7 @@ func (s *ProductService) BatchInsert(ctx context.Context, products []entity.Prod
var (
valuesLines []string
args []interface{}
args []any
)
for _, p := range products {
@@ -58,7 +58,7 @@ func (s *ProductService) BatchInsert(ctx context.Context, products []entity.Prod
}
valuesLines = append(valuesLines, "(?,?,?,?,?)")
args = append(args, []interface{}{p.CategoryID, p.Title, p.ImageURL, p.Price, p.Description}...)
args = append(args, []any{p.CategoryID, p.Title, p.ImageURL, p.Price, p.Description}...)
}
q := fmt.Sprintf("INSERT INTO %s (category_id, title, image_url, price, description) VALUES %s;",
@@ -105,6 +105,6 @@ var productUpdateSchema = map[string]reflect.Kind{
// PartialUpdate accepts a key-value map to
// update the record based on the given "id".
func (s *ProductService) PartialUpdate(ctx context.Context, id int64, attrs map[string]interface{}) (int, error) {
func (s *ProductService) PartialUpdate(ctx context.Context, id int64, attrs map[string]any) (int, error) {
return s.Service.PartialUpdate(ctx, id, productUpdateSchema, attrs)
}

View File

@@ -57,7 +57,7 @@ func (db *MySQL) Drop(database string) error {
}
// Select performs the SELECT query for this database (dsn database name is required).
func (db *MySQL) Select(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
func (db *MySQL) Select(ctx context.Context, dest any, query string, args ...any) error {
rows, err := db.Conn.QueryContext(ctx, query, args...)
if err != nil {
return err
@@ -99,7 +99,7 @@ func (db *MySQL) Select(ctx context.Context, dest interface{}, query string, arg
}
// Get same as `Select` but it moves the cursor to the first result.
func (db *MySQL) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error {
func (db *MySQL) Get(ctx context.Context, dest any, query string, args ...any) error {
rows, err := db.Conn.QueryContext(ctx, query, args...)
if err != nil {
return err
@@ -118,6 +118,6 @@ func (db *MySQL) Get(ctx context.Context, dest interface{}, query string, args .
// Exec executes a query. It does not return any rows.
// Use the first output parameter to count the affected rows on UPDATE, INSERT, or DELETE.
func (db *MySQL) Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error) {
func (db *MySQL) Exec(ctx context.Context, query string, args ...any) (sql.Result, error) {
return db.Conn.ExecContext(ctx, query, args...)
}

View File

@@ -38,7 +38,7 @@ func (s *Service) RecordInfo() Record {
var ErrNoRows = sql.ErrNoRows
// GetByID binds a single record from the databases to the "dest".
func (s *Service) GetByID(ctx context.Context, dest interface{}, id int64) error {
func (s *Service) GetByID(ctx context.Context, dest any, id int64) error {
q := fmt.Sprintf("SELECT * FROM %s WHERE %s = ? LIMIT 1", s.rec.TableName(), s.rec.PrimaryKey())
err := s.db.Get(ctx, dest, q, id)
return err
@@ -70,14 +70,14 @@ type ListOptions struct {
OrderByColumn string
Order string // "ASC" or "DESC" (could be a bool type instead).
WhereColumn string
WhereValue interface{}
WhereValue any
}
// Where accepts a column name and column value to set
// on the WHERE clause of the result query.
// It returns a new `ListOptions` value.
// Note that this is a basic implementation which just takes care our current needs.
func (opt ListOptions) Where(colName string, colValue interface{}) ListOptions {
func (opt ListOptions) Where(colName string, colValue any) ListOptions {
opt.WhereColumn = colName
opt.WhereValue = colValue
return opt
@@ -85,7 +85,7 @@ func (opt ListOptions) Where(colName string, colValue interface{}) ListOptions {
// BuildQuery returns the query and the arguments that
// should be form a SELECT command.
func (opt ListOptions) BuildQuery() (q string, args []interface{}) {
func (opt ListOptions) BuildQuery() (q string, args []any) {
q = fmt.Sprintf("SELECT * FROM %s", opt.Table)
if opt.WhereColumn != "" && opt.WhereValue != nil {
@@ -122,7 +122,7 @@ func ParseListOptions(q url.Values) ListOptions {
// List binds one or more records from the database to the "dest".
// If the record supports ordering then it will sort by the `Sorted.OrderBy` column name(s).
// Use the "order" input parameter to set a descending order ("DESC").
func (s *Service) List(ctx context.Context, dest interface{}, opts ListOptions) error {
func (s *Service) List(ctx context.Context, dest any, opts ListOptions) error {
// Set table and order by column from record info for `List` by options
// so it can be more flexible to perform read-only calls of other table's too.
if opts.Table == "" {
@@ -160,14 +160,14 @@ var ErrUnprocessable = errors.New("invalid entity")
// PartialUpdate accepts a columns schema and a key-value map to
// update the record based on the given "id".
// Note: Trivial string, int and boolean type validations are performed here.
func (s *Service) PartialUpdate(ctx context.Context, id int64, schema map[string]reflect.Kind, attrs map[string]interface{}) (int, error) {
func (s *Service) PartialUpdate(ctx context.Context, id int64, schema map[string]reflect.Kind, attrs map[string]any) (int, error) {
if len(schema) == 0 || len(attrs) == 0 {
return 0, nil
}
var (
keyLines []string
values []interface{}
values []any
)
for key, kind := range schema {

View File

@@ -7,9 +7,9 @@ import (
// Database is an interface which a database(sql) should implement.
type Database interface {
Get(ctx context.Context, dest interface{}, q string, args ...interface{}) error
Select(ctx context.Context, dest interface{}, q string, args ...interface{}) error
Exec(ctx context.Context, q string, args ...interface{}) (sql.Result, error)
Get(ctx context.Context, dest any, q string, args ...any) error
Select(ctx context.Context, dest any, q string, args ...any) error
Exec(ctx context.Context, q string, args ...any) (sql.Result, error)
}
// Record should represent a database record.

View File

@@ -150,7 +150,7 @@ func main() {
var body patchParam
ctx.ReadJSON(&body)
app.Logger().Println(body)
if err := tx.Model(&user).Updates(map[string]interface{}{"username": body.Data.UserName, "password": body.Data.Password}).Error; err != nil {
if err := tx.Model(&user).Updates(map[string]any{"username": body.Data.UserName, "password": body.Data.Password}).Error; err != nil {
app.Logger().Fatalf("update record failed")
tx.Rollback()
ctx.JSON(iris.Map{

View File

@@ -1,6 +1,6 @@
module myapp
go 1.24.3
go 1.25
require (
github.com/kataras/golog v0.1.13

View File

@@ -12,7 +12,7 @@ import (
type personTableType struct {
s parse.StructInfo
z []interface{}
z []any
}
// Schema returns a schema name in SQL database ("").
@@ -63,9 +63,9 @@ func (s Person) String() string {
}
// Values returns a slice of struct or record field values.
// Returned interface{} values are never untyped nils.
func (s *Person) Values() []interface{} {
return []interface{}{
// Returned any values are never untyped nils.
func (s *Person) Values() []any {
return []any{
s.ID,
s.Name,
s.Email,
@@ -75,9 +75,9 @@ func (s *Person) Values() []interface{} {
}
// Pointers returns a slice of pointers to struct or record fields.
// Returned interface{} values are never untyped nils.
func (s *Person) Pointers() []interface{} {
return []interface{}{
// Returned any values are never untyped nils.
func (s *Person) Pointers() []any {
return []any{
&s.ID,
&s.Name,
&s.Email,
@@ -97,14 +97,14 @@ func (s *Person) Table() reform.Table {
}
// PKValue returns a value of primary key for that record.
// Returned interface{} value is never untyped nil.
func (s *Person) PKValue() interface{} {
// Returned any value is never untyped nil.
func (s *Person) PKValue() any {
return s.ID
}
// PKPointer returns a pointer to primary key field for that record.
// Returned interface{} value is never untyped nil.
func (s *Person) PKPointer() interface{} {
// Returned any value is never untyped nil.
func (s *Person) PKPointer() any {
return &s.ID
}
@@ -114,7 +114,7 @@ func (s *Person) HasPK() bool {
}
// SetPK sets record primary key.
func (s *Person) SetPK(pk interface{}) {
func (s *Person) SetPK(pk any) {
if i64, ok := pk.(int64); ok {
s.ID = int32(i64)
} else {

View File

@@ -51,7 +51,7 @@ func main() {
app.Get("/insert", func(ctx iris.Context) {
res, err := db.NamedExec(`INSERT INTO person (first_name,last_name,email) VALUES (:first,:last,:email)`,
map[string]interface{}{
map[string]any{
"first": "John",
"last": "Doe",
"email": "johndoe@example.com",