mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
update dependencies
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
const debug = true
|
||||
|
||||
func debugf(format string, args ...interface{}) {
|
||||
func debugf(format string, args ...any) {
|
||||
if !debug {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
6
_examples/database/mysql/cache/groupcache.go
vendored
6
_examples/database/mysql/cache/groupcache.go
vendored
@@ -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:]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
module myapp
|
||||
|
||||
go 1.24.3
|
||||
go 1.25
|
||||
|
||||
require (
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user