我一直在使用 2 个由OpenAPI 生成器在单独的包中生成的 SDK,它们共享在不同包中重复的相同代码foo
,bar
:
package foo
// there's the exact same piece of code under another package bar
// GenericOpenAPIError Provides access to the body, error and model on returned errors.
type GenericOpenAPIError struct {
...
model interface{}
}
// Model returns the unpacked model of the error
func (e GenericOpenAPIError) Model() interface{} {
return e.model
}
// Failure Provides information about problems encountered while performing an operation.
type Failure struct {
// List of errors which caused this operation to fail
Errors []Error `json:"errors"`
}
// GetErrors returns the Errors field value
func (o *Failure) GetErrors() []Error {...}
// Error Describes a particular error encountered while performing an operation.
type Error struct {
...
// A human-readable explanation specific to this occurrence of the problem.
Detail *string `json:"detail,omitempty"`
...
}
另外,有一个应用程序,我在其中使用了两个 SDK:,并从错误列表foo中bar提取了第一个错误,我在其中尝试将错误转换为每个 SDK 的错误类型,因此必须复制代码。1.18有没有一种方法可以使用支持泛型的方法来简化它?
Cats萌萌
相关分类