add variadic #302

Merged
vtolstov merged 2 commits from devstigneev/micro:issue_296 into master 2024-02-29 01:27:34 +03:00
Showing only changes of commit 4fa0b2c82c - Show all commits

View File

@ -152,27 +152,24 @@ func ContentType(ct string) Option {
// Metadata pass additional metadata // Metadata pass additional metadata
func Metadata(md ...any) Option { func Metadata(md ...any) Option {
result := metadata.Metadata{} var result metadata.Metadata
if len(md) == 1 {
if len(md) > 1 {
var tmp []string
for _, val := range md {
switch vt := val.(type) {
case string:
tmp = append(tmp, vt)
default:
return func(src interface{}) error {
return Set(src, result, ".Metadata")
}
}
}
result.Set(tmp...)
} else if len(md) == 1 {
switch vt := md[0].(type) { switch vt := md[0].(type) {
case metadata.Metadata: case metadata.Metadata:
result = metadata.Copy(vt) result = metadata.Copy(vt)
case map[string]string: case map[string]string:
result = metadata.Copy(vt) result = metadata.Copy(vt)
default:
result = metadata.New(0)
}
} else {
result = metadata.New(len(md) / 2)
for idx := 0; idx < len(md)/2; idx += 2 {
k, kok := md[idx].(string)
v, vok := md[idx+1].(string)
if kok && vok {
result.Set(k, v)
}
} }
} }