Replies: 4 comments 2 replies
-
我认为应该支持泛型
|
Beta Was this translation helpful? Give feedback.
-
是否能支持 枚举类型? |
Beta Was this translation helpful? Give feedback.
-
I think it is necessary to support 'any' type. I have a task where I provide json logs of smart devices to the front-end. And the data reported by it is completely different at different time, so it cannot be formatted as a unified map result. I have to keep the json form of request results for the front-end to use, rather than strings. So using 'any' is probably the best solution. Such as the following two forms of data: {"msg": {"A": 1,"B":2,"C":"result"}} {"msg": {"B":1,"D":"result2"}} Data content richness is determined by the type of business, and the framework should provide more adequate ways to support it, rather than increasing the burden of serialization and deserialization for the sake of "specification". 我认为支持泛型 如下面两种数据形式: {"msg": {"A": 1,"B":2,"C":"result"}} {"msg": {"B":1,"D":"result2"}} 数据内容丰富性是业务类型决定的,框架应该提供更足够的支持方式,而非为了「规范」让开发增加序列化、反序列化的负担。 |
Beta Was this translation helpful? Give feedback.
-
希望支持,原因如下: type Event struct {
APIResource
// The connected account that originates the event.
Account string `json:"account"`
// The Stripe API version used to render `data`. This property is populated only for events on or after October 31, 2014.
APIVersion string `json:"api_version"`
// Time at which the object was created. Measured in seconds since the Unix epoch.
Created int64 `json:"created"`
Data *EventData `json:"data"`
// Unique identifier for the object.
ID string `json:"id"`
// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
Livemode bool `json:"livemode"`
// String representing the object's type. Objects of the same type share the same value.
Object string `json:"object"`
// Number of webhooks that haven't been successfully delivered (for example, to return a 20x response) to the URLs you specify.
PendingWebhooks int64 `json:"pending_webhooks"`
// Information on the API request that triggers the event.
Request *EventRequest `json:"request"`
// Description of the event (for example, `invoice.created` or `charge.refunded`).
Type EventType `json:"type"`
} type EventData struct {
// Object is a raw mapping of the API resource contained in the event.
// Although marked with json:"-", it's still populated independently by
// a custom UnmarshalJSON implementation.
// Object containing the API resource relevant to the event. For example, an `invoice.created` event will have a full [invoice object](https://stripe.com/docs/api#invoice_object) as the value of the object key.
Object map[string]interface{} `json:"-"`
// Object containing the names of the updated attributes and their values prior to the event (only included in events of type `*.updated`). If an array attribute has any updated elements, this object contains the entire array. In Stripe API versions 2017-04-06 or earlier, an updated array attribute in this object includes only the updated array elements.
PreviousAttributes map[string]interface{} `json:"previous_attributes"`
Raw json.RawMessage `json:"object"`
} 其中EventData中就有interface{}定义。 2.在k8s中,我通常使用dynamic.Interface客户端使用GVR管理资源,这样我只需要写一个通用的逻辑就可以管理k8s几乎所有资源,否则我需要为每一个资源(Pod/Deploy/Job或者是三方的CRD,如果是三方,可能还需要引入三方的SDK)如果为每一个资源特殊处理,代码会非常的长,非常的麻烦。而dynamic.Interface接口是这么定义的: package dynamic
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type Interface interface {
Resource(resource schema.GroupVersionResource) NamespaceableResourceInterface
}
type ResourceInterface interface {
Create(ctx context.Context, obj *unstructured.Unstructured, options metav1.CreateOptions, subresources ...string) (*unstructured.Unstructured, error)
Update(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions, subresources ...string) (*unstructured.Unstructured, error)
UpdateStatus(ctx context.Context, obj *unstructured.Unstructured, options metav1.UpdateOptions) (*unstructured.Unstructured, error)
Delete(ctx context.Context, name string, options metav1.DeleteOptions, subresources ...string) error
DeleteCollection(ctx context.Context, options metav1.DeleteOptions, listOptions metav1.ListOptions) error
Get(ctx context.Context, name string, options metav1.GetOptions, subresources ...string) (*unstructured.Unstructured, error)
List(ctx context.Context, opts metav1.ListOptions) (*unstructured.UnstructuredList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*unstructured.Unstructured, error)
Apply(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions, subresources ...string) (*unstructured.Unstructured, error)
ApplyStatus(ctx context.Context, name string, obj *unstructured.Unstructured, options metav1.ApplyOptions) (*unstructured.Unstructured, error)
} type Unstructured struct {
// Object is a JSON compatible map with string, float, int, bool, []interface{}, or
// map[string]interface{}
// children.
Object map[string]interface{}
} Unstructured有interface{}定义。 |
Beta Was this translation helpful? Give feedback.
-
In the API description language, considering that all request and response data should be concrete data and types, that is, each field should be strongly typed, so there is no support for generics and any types, do you think it is reasonable? What do you think?
Beta Was this translation helpful? Give feedback.
All reactions