mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
any
This commit is contained in:
@ -13,7 +13,7 @@ import (
|
||||
|
||||
// 下划线
|
||||
type SnakeCase struct {
|
||||
Value interface{}
|
||||
Value any
|
||||
}
|
||||
|
||||
func (c SnakeCase) MarshalJSON() ([]byte, error) {
|
||||
@ -35,7 +35,7 @@ func (c SnakeCase) MarshalJSON() ([]byte, error) {
|
||||
|
||||
// 驼峰
|
||||
type CamelCase struct {
|
||||
Value interface{}
|
||||
Value any
|
||||
}
|
||||
|
||||
func (c CamelCase) MarshalJSON() ([]byte, error) {
|
||||
@ -106,7 +106,7 @@ func NewBuffer() *Buffer {
|
||||
return &Buffer{Buffer: new(bytes.Buffer)}
|
||||
}
|
||||
|
||||
func (b *Buffer) Append(i interface{}) *Buffer {
|
||||
func (b *Buffer) Append(i any) *Buffer {
|
||||
switch val := i.(type) {
|
||||
case int:
|
||||
b.append(strconv.Itoa(val))
|
||||
|
@ -7,18 +7,18 @@ import (
|
||||
)
|
||||
|
||||
// 结构转换为json字符串
|
||||
func StructToJsonIndent(obj interface{}) string {
|
||||
func StructToJsonIndent(obj any) string {
|
||||
b, _ := MarshalIndent(obj, "", " ")
|
||||
return bytesconv.BytesToString(b)
|
||||
}
|
||||
|
||||
// 结构转换为json字符串
|
||||
func StructToJson(obj interface{}) string {
|
||||
func StructToJson(obj any) string {
|
||||
b, _ := Marshal(obj)
|
||||
return bytesconv.BytesToString(b)
|
||||
}
|
||||
|
||||
func StructToMap(obj interface{}) map[string]interface{} {
|
||||
func StructToMap(obj any) map[string]any {
|
||||
typ := reflect.TypeOf(obj)
|
||||
|
||||
kind := typ.Kind()
|
||||
@ -28,7 +28,7 @@ func StructToMap(obj interface{}) map[string]interface{} {
|
||||
|
||||
val := reflect.ValueOf(obj)
|
||||
|
||||
m := make(map[string]interface{})
|
||||
m := make(map[string]any)
|
||||
for i := 0; i < val.NumField(); i++ {
|
||||
m[typ.Field(i).Name] = val.Field(i).Interface()
|
||||
}
|
||||
@ -36,8 +36,8 @@ func StructToMap(obj interface{}) map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func StructToMapViaJson(obj interface{}) map[string]interface{} {
|
||||
m := make(map[string]interface{})
|
||||
func StructToMapViaJson(obj any) map[string]any {
|
||||
m := make(map[string]any)
|
||||
|
||||
j, _ := Marshal(obj)
|
||||
_ = Unmarshal(j, &m)
|
||||
@ -45,8 +45,8 @@ func StructToMapViaJson(obj interface{}) map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func toMap(obj interface{}) map[string]interface{} {
|
||||
if h, ok := obj.(map[string]interface{}); ok {
|
||||
func toMap(obj any) map[string]any {
|
||||
if h, ok := obj.(map[string]any); ok {
|
||||
return h
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user