From 4fa0b2c82cb5aa4d6ead11398c75978ddb949389 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 29 Feb 2024 01:26:09 +0300 Subject: [PATCH] fixup Signed-off-by: Vasiliy Tolstov --- options/options.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/options/options.go b/options/options.go index 2e611b75..cbcf15fd 100644 --- a/options/options.go +++ b/options/options.go @@ -152,27 +152,24 @@ func ContentType(ct string) Option { // Metadata pass additional metadata func Metadata(md ...any) Option { - result := metadata.Metadata{} - - 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 { + var result metadata.Metadata + if len(md) == 1 { switch vt := md[0].(type) { case metadata.Metadata: result = metadata.Copy(vt) case map[string]string: 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) + } } }