From 69d0d77a045e6ca452c9815c607ee314f385129e Mon Sep 17 00:00:00 2001 From: "hui.wang" Date: Mon, 21 Feb 2022 18:16:41 +0800 Subject: [PATCH] fix: raw string for regexp.Compile --- xutil/marshal.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xutil/marshal.go b/xutil/marshal.go index 093dabc..150196a 100644 --- a/xutil/marshal.go +++ b/xutil/marshal.go @@ -8,7 +8,7 @@ import ( ) const ( - indentation = 4 + indentation = 2 ) func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag string, yamlKey func(string) string) (string, error) { @@ -35,7 +35,7 @@ func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag s } else { result = fmt.Sprintf("%s %s\n", result, comment) for i := 0; i < value.Len(); i++ { - result = fmt.Sprintf("%s%s -", result, indent) + result = fmt.Sprintf("%s%s-", result, indent) nested, err := YAMLWithComments(value.Index(i).Interface(), atIndent+indentation, yamlTag, usageTag, yamlKey) if err != nil { return err @@ -116,7 +116,7 @@ func YAMLWithComments(data interface{}, atIndent int, yamlTag string, usageTag s } } - reCompact, _ := regexp.Compile("(?m)\\n{2,}") + reCompact, _ := regexp.Compile(`(?m)\\n{2,}`) result = reCompact.ReplaceAllString(result, "\n") return result, nil }