chore: update goctl interface{} to any (#2819)

* chore: update goctl interface{} to any

* chore: update goctl interface{} to any
master
Kevin Wan 2 years ago committed by GitHub
parent ae87114282
commit eab904af64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -143,7 +143,7 @@ func file_hello_proto_rawDescGZIP() []byte {
}
var file_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_hello_proto_goTypes = []interface{}{
var file_hello_proto_goTypes = []any{
(*HelloReq)(nil), // 0: hello.HelloReq
(*HelloResp)(nil), // 1: hello.HelloResp
}
@ -163,7 +163,7 @@ func file_hello_proto_init() {
return
}
if !protoimpl.UnsafeEnabled {
file_hello_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_hello_proto_msgTypes[0].Exporter = func(v any, i int) any {
switch v := v.(*HelloReq); i {
case 0:
return &v.state
@ -175,7 +175,7 @@ func file_hello_proto_init() {
return nil
}
}
file_hello_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
file_hello_proto_msgTypes[1].Exporter = func(v any, i int) any {
switch v := v.(*HelloResp); i {
case 0:
return &v.state

@ -71,7 +71,7 @@ func RegisterGreetServer(s grpc.ServiceRegistrar, srv GreetServer) {
s.RegisterService(&Greet_ServiceDesc, srv)
}
func _Greet_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Greet_SayHello_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
in := new(HelloReq)
if err := dec(in); err != nil {
return nil, err
@ -83,7 +83,7 @@ func _Greet_SayHello_Handler(srv interface{}, ctx context.Context, dec func(inte
Server: srv,
FullMethod: "/hello.Greet/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
return srv.(GreetServer).SayHello(ctx, req.(*HelloReq))
}
return interceptor(ctx, in, info, handler)

@ -322,7 +322,7 @@ func file_hi_proto_rawDescGZIP() []byte {
}
var file_hi_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_hi_proto_goTypes = []interface{}{
var file_hi_proto_goTypes = []any{
(*HiReq)(nil), // 0: hi.HiReq
(*HelloReq)(nil), // 1: hi.HelloReq
(*HiResp)(nil), // 2: hi.HiResp
@ -350,7 +350,7 @@ func file_hi_proto_init() {
return
}
if !protoimpl.UnsafeEnabled {
file_hi_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[0].Exporter = func(v any, i int) any {
switch v := v.(*HiReq); i {
case 0:
return &v.state
@ -362,7 +362,7 @@ func file_hi_proto_init() {
return nil
}
}
file_hi_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[1].Exporter = func(v any, i int) any {
switch v := v.(*HelloReq); i {
case 0:
return &v.state
@ -374,7 +374,7 @@ func file_hi_proto_init() {
return nil
}
}
file_hi_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[2].Exporter = func(v any, i int) any {
switch v := v.(*HiResp); i {
case 0:
return &v.state
@ -386,7 +386,7 @@ func file_hi_proto_init() {
return nil
}
}
file_hi_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[3].Exporter = func(v any, i int) any {
switch v := v.(*HelloResp); i {
case 0:
return &v.state
@ -398,7 +398,7 @@ func file_hi_proto_init() {
return nil
}
}
file_hi_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[4].Exporter = func(v any, i int) any {
switch v := v.(*EventReq); i {
case 0:
return &v.state
@ -410,7 +410,7 @@ func file_hi_proto_init() {
return nil
}
}
file_hi_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
file_hi_proto_msgTypes[5].Exporter = func(v any, i int) any {
switch v := v.(*EventResp); i {
case 0:
return &v.state

@ -85,7 +85,7 @@ func RegisterGreetServer(s grpc.ServiceRegistrar, srv GreetServer) {
s.RegisterService(&Greet_ServiceDesc, srv)
}
func _Greet_SayHi_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Greet_SayHi_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
in := new(HiReq)
if err := dec(in); err != nil {
return nil, err
@ -97,13 +97,13 @@ func _Greet_SayHi_Handler(srv interface{}, ctx context.Context, dec func(interfa
Server: srv,
FullMethod: "/hi.Greet/SayHi",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
return srv.(GreetServer).SayHi(ctx, req.(*HiReq))
}
return interceptor(ctx, in, info, handler)
}
func _Greet_SayHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Greet_SayHello_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
in := new(HelloReq)
if err := dec(in); err != nil {
return nil, err
@ -115,7 +115,7 @@ func _Greet_SayHello_Handler(srv interface{}, ctx context.Context, dec func(inte
Server: srv,
FullMethod: "/hi.Greet/SayHello",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
return srv.(GreetServer).SayHello(ctx, req.(*HelloReq))
}
return interceptor(ctx, in, info, handler)
@ -193,7 +193,7 @@ func RegisterEventServer(s grpc.ServiceRegistrar, srv EventServer) {
s.RegisterService(&Event_ServiceDesc, srv)
}
func _Event_AskQuestion_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
func _Event_AskQuestion_Handler(srv any, ctx context.Context, dec func(any) error, interceptor grpc.UnaryServerInterceptor) (any, error) {
in := new(EventReq)
if err := dec(in); err != nil {
return nil, err
@ -205,7 +205,7 @@ func _Event_AskQuestion_Handler(srv interface{}, ctx context.Context, dec func(i
Server: srv,
FullMethod: "/hi.Event/AskQuestion",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
handler := func(ctx context.Context, req any) (any, error) {
return srv.(EventServer).AskQuestion(ctx, req.(*EventReq))
}
return interceptor(ctx, in, info, handler)

@ -55,7 +55,7 @@ func generateModel(ctx *Context) error {
}
output := filepath.Join(ctx.Output, fn+".go")
if err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]interface{}{
if err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]any{
"Type": stringx.From(t).Title(),
"lowerType": stringx.From(t).Untitle(),
"Cache": ctx.Cache,
@ -80,7 +80,7 @@ func generateCustomModel(ctx *Context) error {
}
output := filepath.Join(ctx.Output, fn+".go")
err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]interface{}{
err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]any{
"Type": stringx.From(t).Title(),
"lowerType": stringx.From(t).Untitle(),
"snakeType": stringx.From(t).ToSnake(),
@ -108,7 +108,7 @@ func generateTypes(ctx *Context) error {
}
output := filepath.Join(ctx.Output, fn+".go")
if err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]interface{}{
if err = util.With("model").Parse(text).GoFmt(true).SaveTo(map[string]any{
"Type": stringx.From(t).Title(),
}, output, false); err != nil {
return err

@ -122,7 +122,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByUser(user string) (*User, error) {
userKey := fmt.Sprintf("%s%v", cacheUserPrefix, user)
var resp User
err := m.QueryRowIndex(&resp, userKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where user = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, user); err != nil {
return nil, err
@ -142,7 +142,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByName(name string) (*User, error) {
userNameKey := fmt.Sprintf("%s%v", cacheUserNamePrefix, name)
var resp User
err := m.QueryRowIndex(&resp, userNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where name = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, name); err != nil {
return nil, err
@ -162,7 +162,7 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
func (m *defaultUserModel) FindOneByMobile(mobile string) (*User, error) {
userMobileKey := fmt.Sprintf("%s%v", cacheUserMobilePrefix, mobile)
var resp User
err := m.QueryRowIndex(&resp, userMobileKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, userMobileKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where mobile = ? limit 1", userRows, m.table)
if err := conn.QueryRow(&resp, query, mobile); err != nil {
return nil, err
@ -205,11 +205,11 @@ goctl model 为go-zero下的工具模块中的组件之一目前支持识别m
return err
}
func (m *defaultUserModel) formatPrimary(primary interface{}) string {
func (m *defaultUserModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheUserIdPrefix, primary)
}
func (m *defaultUserModel) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error {
func (m *defaultUserModel) queryPrimary(conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where id = ? limit 1", userRows, m.table)
return conn.QueryRow(v, query, primary)
}

@ -5,12 +5,12 @@ import (
)
// Deprecated: Use github.com/zeromicro/go-zero/core/stores/builder.RawFieldNames instead.
func FieldNames(in interface{}) []string {
func FieldNames(in any) []string {
return builder.RawFieldNames(in)
}
// Deprecated: Use github.com/zeromicro/go-zero/core/stores/builder.RawFieldNames instead.
func RawFieldNames(in interface{}, postgresSql ...bool) []string {
func RawFieldNames(in any, postgresSql ...bool) []string {
return builder.RawFieldNames(in, postgresSql...)
}

@ -33,7 +33,7 @@ func genDelete(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("delete").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"upperStartCamelObject": camel,
"withCache": withCache,
"containsIndexCache": table.ContainsUniqueCacheKey,
@ -57,7 +57,7 @@ func genDelete(table Table, withCache, postgreSql bool) (string, string, error)
deleteMethodOut, err := util.With("deleteMethod").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"lowerStartCamelPrimaryKey": util.EscapeGolangKeyword(stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle()),
"dataType": table.PrimaryKey.DataType,
"data": table,

@ -37,7 +37,7 @@ func genField(table Table, field *parser.Field) (string, error) {
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"name": util.SafeString(field.Name.ToCamel()),
"type": field.DataType,
"tag": tag,

@ -16,7 +16,7 @@ func genFindOne(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("findOne").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"upperStartCamelObject": camel,
"lowerStartCamelObject": stringx.From(camel).Untitle(),
@ -39,7 +39,7 @@ func genFindOne(table Table, withCache, postgreSql bool) (string, string, error)
findOneMethod, err := util.With("findOneMethod").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"upperStartCamelObject": camel,
"lowerStartCamelPrimaryKey": util.EscapeGolangKeyword(stringx.From(table.PrimaryKey.Name.ToCamel()).Untitle()),
"dataType": table.PrimaryKey.DataType,

@ -28,7 +28,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
for _, key := range table.UniqueCacheKey {
in, paramJoinString, originalFieldString := convertJoin(key, postgreSql)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"upperField": key.FieldNameJoin.Camel().With("").Source(),
"in": in,
@ -68,7 +68,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
if len(inJoin) > 0 {
in = inJoin.With(", ").Source()
}
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"upperField": key.FieldNameJoin.Camel().With("").Source(),
"in": in,
@ -88,7 +88,7 @@ func genFindOneByField(table Table, withCache, postgreSql bool) (*findOneCode, e
return nil, err
}
out, err := util.With("findOneByFieldExtraMethod").Parse(text).Execute(map[string]interface{}{
out, err := util.With("findOneByFieldExtraMethod").Parse(text).Execute(map[string]any{
"upperStartCamelObject": camelTableName,
"primaryKeyLeft": table.PrimaryCacheKey.VarLeft,
"lowerStartCamelObject": stringx.From(camelTableName).Untitle(),

@ -354,7 +354,7 @@ func (g *defaultGenerator) genModelCustom(in parser.Table, withCache bool) (stri
t := util.With("model-custom").
Parse(text).
GoFmt(true)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"pkg": g.pkg,
"withCache": withCache,
"upperStartCamelObject": in.Name.ToCamel(),
@ -375,7 +375,7 @@ func (g *defaultGenerator) executeModel(table Table, code *code) (*bytes.Buffer,
t := util.With("model").
Parse(text).
GoFmt(true)
output, err := t.Execute(map[string]interface{}{
output, err := t.Execute(map[string]any{
"pkg": g.pkg,
"imports": code.importsCode,
"vars": code.varsCode,

@ -30,7 +30,7 @@ func genImports(table Table, withCache, timeImport bool) (string, error) {
return "", err
}
buffer, err := util.With("import").Parse(text).Execute(map[string]interface{}{
buffer, err := util.With("import").Parse(text).Execute(map[string]any{
"time": timeImport,
"containsPQ": table.ContainsPQ,
"data": table,

@ -58,7 +58,7 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
output, err := util.With("insert").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"upperStartCamelObject": camel,
"lowerStartCamelObject": stringx.From(camel).Untitle(),
@ -78,7 +78,7 @@ func genInsert(table Table, withCache, postgreSql bool) (string, string, error)
return "", "", err
}
insertMethodOutput, err := util.With("insertMethod").Parse(text).Execute(map[string]interface{}{
insertMethodOutput, err := util.With("insertMethod").Parse(text).Execute(map[string]any{
"upperStartCamelObject": camel,
"data": table,
})

@ -21,7 +21,7 @@ func genNew(table Table, withCache, postgreSql bool) (string, error) {
output, err := util.With("new").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"table": t,
"withCache": withCache,
"upperStartCamelObject": table.Name.ToCamel(),

@ -14,7 +14,7 @@ func genTableName(table Table) (string, error) {
output, err := util.With("tableName").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"tableName": table.Name.Source(),
"upperStartCamelObject": table.Name.ToCamel(),
})

@ -16,7 +16,7 @@ func genTag(table Table, in string) (string, error) {
return "", err
}
output, err := util.With("tag").Parse(text).Execute(map[string]interface{}{
output, err := util.With("tag").Parse(text).Execute(map[string]any{
"field": in,
"data": table,
})

@ -21,7 +21,7 @@ func genTypes(table Table, methods string, withCache bool) (string, error) {
output, err := util.With("types").
Parse(text).
Execute(map[string]interface{}{
Execute(map[string]any{
"withCache": withCache,
"method": methods,
"upperStartCamelObject": table.Name.ToCamel(),

@ -95,7 +95,7 @@ func genUpdate(table Table, withCache, postgreSql bool) (
}
updateMethodOutput, err := util.With("updateMethod").Parse(text).Execute(
map[string]interface{}{
map[string]any{
"upperStartCamelObject": camelTableName,
"data": table,
},

@ -26,7 +26,7 @@ func genVars(table Table, withCache, postgreSql bool) (string, error) {
}
output, err := util.With("var").Parse(text).
GoFmt(true).Execute(map[string]interface{}{
GoFmt(true).Execute(map[string]any{
"lowerStartCamelObject": stringx.From(camel).Untitle(),
"upperStartCamelObject": camel,
"cacheKeys": strings.Join(keys, "\n"),

@ -29,7 +29,7 @@ type (
ColumnType string `db:"COLUMN_TYPE"`
Extra string `db:"EXTRA"`
Comment string `db:"COLUMN_COMMENT"`
ColumnDefault interface{} `db:"COLUMN_DEFAULT"`
ColumnDefault any `db:"COLUMN_DEFAULT"`
IsNullAble string `db:"IS_NULLABLE"`
OrdinalPosition int `db:"ORDINAL_POSITION"`
}

@ -112,7 +112,7 @@ func (m *PostgreSqlModel) getColumns(schema, table string, in []*PostgreColumn)
var list []*Column
for _, e := range in {
var dft interface{}
var dft any
if len(e.ColumnDefault.String) > 0 {
dft = e.ColumnDefault
}

@ -1,8 +1,8 @@
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary interface{}) string {
func (m *default{{.upperStartCamelObject}}Model) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", {{.primaryKeyLeft}}, primary)
}
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
func (m *default{{.upperStartCamelObject}}Model) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryField}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table )
return conn.QueryRowCtx(ctx, v, query, primary)
}

@ -1,7 +1,7 @@
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where {{.originalField}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, {{.lowerStartCamelField}}); err != nil {
return nil, err

@ -1,7 +1,7 @@
func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where {{.originalPrimaryKey}} = {{if .postgreSql}}$1{{else}}?{{end}} limit 1", {{.lowerStartCamelObject}}Rows, m.table)
return conn.QueryRowCtx(ctx, v, query, {{.lowerStartCamelPrimaryKey}})
})

@ -71,7 +71,7 @@ func (m *defaultStudentModel) Insert(data Student) (sql.Result, error) {
func (m *defaultStudentModel) FindOne(id int64) (*Student, error) {
studentIdKey := fmt.Sprintf("%s%v", cacheStudentIdPrefix, id)
var resp Student
err := m.QueryRow(&resp, studentIdKey, func(conn sqlx.SqlConn, v interface{}) error {
err := m.QueryRow(&resp, studentIdKey, func(conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", studentRows, m.table)
return conn.QueryRow(v, query, id)
})
@ -88,7 +88,7 @@ func (m *defaultStudentModel) FindOne(id int64) (*Student, error) {
func (m *defaultStudentModel) FindOneByClassName(class, name string) (*Student, error) {
studentClassNameKey := fmt.Sprintf("%s%v%v", cacheStudentClassNamePrefix, class, name)
var resp Student
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
err := m.QueryRowIndex(&resp, studentClassNameKey, m.formatPrimary, func(conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `class` = ? and `name` = ? limit 1", studentRows, m.table)
if err := conn.QueryRow(&resp, query, class, name); err != nil {
return nil, err
@ -124,11 +124,11 @@ func (m *defaultStudentModel) Delete(id int64, className, studentName string) er
return err
}
func (m *defaultStudentModel) formatPrimary(primary interface{}) string {
func (m *defaultStudentModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheStudentIdPrefix, primary)
}
func (m *defaultStudentModel) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error {
func (m *defaultStudentModel) queryPrimary(conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", studentRows, m.table)
return conn.QueryRow(v, query, primary)
}

@ -27,13 +27,13 @@ type rowsScanner interface {
Columns() ([]string, error)
Err() error
Next() bool
Scan(v ...interface{}) error
Scan(v ...any) error
}
func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
func getTaggedFieldValueMap(v reflect.Value) (map[string]any, error) {
rt := mapping.Deref(v.Type())
size := rt.NumField()
result := make(map[string]interface{}, size)
result := make(map[string]any, size)
for i := 0; i < size; i++ {
key := parseTagName(rt.Field(i))
@ -63,7 +63,7 @@ func getTaggedFieldValueMap(v reflect.Value) (map[string]interface{}, error) {
return result, nil
}
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]interface{}, error) {
func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([]any, error) {
fields := unwrapFields(v)
if strict && len(columns) < len(fields) {
return nil, ErrNotMatchDestination
@ -74,7 +74,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
return nil, err
}
values := make([]interface{}, len(columns))
values := make([]any, len(columns))
if len(taggedMap) == 0 {
for i := 0; i < len(values); i++ {
valueField := fields[i]
@ -100,7 +100,7 @@ func mapStructFieldsIntoSlice(v reflect.Value, columns []string, strict bool) ([
if tagged, ok := taggedMap[column]; ok {
values[i] = tagged
} else {
var anonymous interface{}
var anonymous any
values[i] = &anonymous
}
}
@ -119,7 +119,7 @@ func parseTagName(field reflect.StructField) string {
return options[0]
}
func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRow(v any, scanner rowsScanner, strict bool) error {
if !scanner.Next() {
if err := scanner.Err(); err != nil {
return err
@ -161,7 +161,7 @@ func unmarshalRow(v interface{}, scanner rowsScanner, strict bool) error {
}
}
func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
func unmarshalRows(v any, scanner rowsScanner, strict bool) error {
rv := reflect.ValueOf(v)
if err := mapping.ValidatePtr(&rv); err != nil {
return err
@ -181,7 +181,7 @@ func unmarshalRows(v interface{}, scanner rowsScanner, strict bool) error {
rve.Set(reflect.Append(rve, reflect.Indirect(item)))
}
}
fillFn := func(value interface{}) error {
fillFn := func(value any) error {
if rve.CanSet() {
if err := scanner.Scan(value); err != nil {
return err

@ -26,12 +26,12 @@ func NewMockConn(db *sql.DB) *MockConn {
}
// Exec executes sql and returns the result
func (conn *MockConn) Exec(query string, args ...interface{}) (sql.Result, error) {
func (conn *MockConn) Exec(query string, args ...any) (sql.Result, error) {
return exec(conn.db, query, args...)
}
// ExecCtx executes sql and returns the result
func (conn *MockConn) ExecCtx(_ context.Context, query string, args ...interface{}) (sql.Result, error) {
func (conn *MockConn) ExecCtx(_ context.Context, query string, args ...any) (sql.Result, error) {
return exec(conn.db, query, args...)
}
@ -47,50 +47,50 @@ func (conn *MockConn) PrepareCtx(_ context.Context, query string) (sqlx.StmtSess
}
// QueryRow executes sql and returns a query row
func (conn *MockConn) QueryRow(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRow(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, true)
}, q, args...)
}
// QueryRowCtx executes sql and returns a query row
func (conn *MockConn) QueryRowCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRow(v, query, args...)
}
// QueryRowPartial executes sql and returns a partial query row
func (conn *MockConn) QueryRowPartial(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRowPartial(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, false)
}, q, args...)
}
// QueryRowPartialCtx executes sql and returns a partial query row
func (conn *MockConn) QueryRowPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowPartialCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRowPartial(v, query, args...)
}
// QueryRows executes sql and returns query rows
func (conn *MockConn) QueryRows(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRows(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, true)
}, q, args...)
}
// QueryRowsCtx executes sql and returns query rows
func (conn *MockConn) QueryRowsCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowsCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRows(v, query, args...)
}
// QueryRowsPartial executes sql and returns partial query rows
func (conn *MockConn) QueryRowsPartial(v interface{}, q string, args ...interface{}) error {
func (conn *MockConn) QueryRowsPartial(v any, q string, args ...any) error {
return query(conn.db, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, false)
}, q, args...)
}
// QueryRowsPartialCtx executes sql and returns partial query rows
func (conn *MockConn) QueryRowsPartialCtx(_ context.Context, v interface{}, query string, args ...interface{}) error {
func (conn *MockConn) QueryRowsPartialCtx(_ context.Context, v any, query string, args ...any) error {
return conn.QueryRowsPartial(v, query, args...)
}
@ -113,50 +113,50 @@ func (s statement) Close() error {
return s.stmt.Close()
}
func (s statement) Exec(args ...interface{}) (sql.Result, error) {
func (s statement) Exec(args ...any) (sql.Result, error) {
return execStmt(s.stmt, args...)
}
func (s statement) ExecCtx(_ context.Context, args ...interface{}) (sql.Result, error) {
func (s statement) ExecCtx(_ context.Context, args ...any) (sql.Result, error) {
return s.Exec(args...)
}
func (s statement) QueryRow(v interface{}, args ...interface{}) error {
func (s statement) QueryRow(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, true)
}, args...)
}
func (s statement) QueryRowCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowCtx(_ context.Context, v any, args ...any) error {
return s.QueryRow(v, args...)
}
func (s statement) QueryRowPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowPartial(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRow(v, rows, false)
}, args...)
}
func (s statement) QueryRowPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowPartialCtx(_ context.Context, v any, args ...any) error {
return s.QueryRowPartial(v, args...)
}
func (s statement) QueryRows(v interface{}, args ...interface{}) error {
func (s statement) QueryRows(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, true)
}, args...)
}
func (s statement) QueryRowsCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowsCtx(_ context.Context, v any, args ...any) error {
return s.QueryRows(v, args...)
}
func (s statement) QueryRowsPartial(v interface{}, args ...interface{}) error {
func (s statement) QueryRowsPartial(v any, args ...any) error {
return queryStmt(s.stmt, func(rows *sql.Rows) error {
return unmarshalRows(v, rows, false)
}, args...)
}
func (s statement) QueryRowsPartialCtx(_ context.Context, v interface{}, args ...interface{}) error {
func (s statement) QueryRowsPartialCtx(_ context.Context, v any, args ...any) error {
return s.QueryRowsPartial(v, args...)
}

@ -13,7 +13,7 @@ import (
const slowThreshold = time.Millisecond * 500
func exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error) {
func exec(db *sql.DB, q string, args ...any) (sql.Result, error) {
tx, err := db.Begin()
if err != nil {
return nil, err
@ -48,7 +48,7 @@ func exec(db *sql.DB, q string, args ...interface{}) (sql.Result, error) {
return result, err
}
func execStmt(conn *sql.Stmt, args ...interface{}) (sql.Result, error) {
func execStmt(conn *sql.Stmt, args ...any) (sql.Result, error) {
stmt := fmt.Sprint(args...)
startTime := timex.Now()
result, err := conn.Exec(args...)
@ -65,7 +65,7 @@ func execStmt(conn *sql.Stmt, args ...interface{}) (sql.Result, error) {
return result, err
}
func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...interface{}) error {
func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...any) error {
tx, err := db.Begin()
if err != nil {
return err
@ -102,7 +102,7 @@ func query(db *sql.DB, scanner func(*sql.Rows) error, q string, args ...interfac
return scanner(rows)
}
func queryStmt(conn *sql.Stmt, scanner func(*sql.Rows) error, args ...interface{}) error {
func queryStmt(conn *sql.Stmt, scanner func(*sql.Rows) error, args ...any) error {
stmt := fmt.Sprint(args...)
startTime := timex.Now()
rows, err := conn.Query(args...)

@ -41,7 +41,7 @@ func escape(input string) string {
return b.String()
}
func format(query string, args ...interface{}) (string, error) {
func format(query string, args ...any) (string, error) {
numArgs := len(args)
if numArgs == 0 {
return query, nil

@ -79,14 +79,14 @@ func (m mono) createAPIProject() {
logx.Must(err)
}
logx.Must(util.With("logic").Parse(apiLogicContent).SaveTo(map[string]interface{}{
logx.Must(util.With("logic").Parse(apiLogicContent).SaveTo(map[string]any{
"svcPkg": svcPkg,
"typesPkg": typesPkg,
"rpcClientPkg": rpcClientPkg,
"callRPC": m.callRPC,
}, logicFile, true))
logx.Must(util.With("svc").Parse(svcContent).SaveTo(map[string]interface{}{
logx.Must(util.With("svc").Parse(svcContent).SaveTo(map[string]any{
"rpcClientPkg": rpcClientPkg,
"configPkg": configPkg,
"callRPC": m.callRPC,

@ -125,27 +125,27 @@ func (i *ideaConsole) Info(format string, a ...any) {
fmt.Println(msg)
}
func (i *ideaConsole) Debug(format string, a ...interface{}) {
func (i *ideaConsole) Debug(format string, a ...any) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.BrightCyan(msg))
}
func (i *ideaConsole) Success(format string, a ...interface{}) {
func (i *ideaConsole) Success(format string, a ...any) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[SUCCESS]: ", msg)
}
func (i *ideaConsole) Warning(format string, a ...interface{}) {
func (i *ideaConsole) Warning(format string, a ...any) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[WARNING]: ", msg)
}
func (i *ideaConsole) Error(format string, a ...interface{}) {
func (i *ideaConsole) Error(format string, a ...any) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[ERROR]: ", msg)
}
func (i *ideaConsole) Fatalln(format string, a ...interface{}) {
func (i *ideaConsole) Fatalln(format string, a ...any) {
i.Error(format, a...)
os.Exit(1)
}
@ -160,7 +160,7 @@ func (i *ideaConsole) Must(err error) {
}
}
func println(msg interface{}) {
func println(msg any) {
value, ok := msg.(aurora.Value)
if !ok {
fmt.Println(msg)
@ -177,27 +177,27 @@ func println(msg interface{}) {
var defaultConsole = &colorConsole{enable: true}
func Success(format string, a ...interface{}) {
func Success(format string, a ...any) {
defaultConsole.Success(format, a...)
}
func Info(format string, a ...interface{}) {
func Info(format string, a ...any) {
defaultConsole.Info(format, a...)
}
func Debug(format string, a ...interface{}) {
func Debug(format string, a ...any) {
defaultConsole.Debug(format, a...)
}
func Warning(format string, a ...interface{}) {
func Warning(format string, a ...any) {
defaultConsole.Warning(format, a...)
}
func Error(format string, a ...interface{}) {
func Error(format string, a ...any) {
defaultConsole.Error(format, a...)
}
func Fatalln(format string, a ...interface{}) {
func Fatalln(format string, a ...any) {
defaultConsole.Fatalln(format, a...)
}

Loading…
Cancel
Save