From 34fd303d990fe37da1c965421da6d603408e0e5f Mon Sep 17 00:00:00 2001 From: C Date: Fri, 7 Apr 2023 11:49:23 +0800 Subject: [PATCH] feat(debug): control log --- tagsugar.go | 7 +++++-- tagsugar_test.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tagsugar.go b/tagsugar.go index f5e5922..7bf71bf 100644 --- a/tagsugar.go +++ b/tagsugar.go @@ -11,6 +11,7 @@ import ( var ( Http = "" + Debug = false hostMap = make(map[string]string, 0) ) @@ -44,7 +45,9 @@ func resolveValue(v reflect.Value, k reflect.Kind) { v, k = getEkByValue(v) resolveValue(v, k) default: - log.Print("Ignore kind: " + k.String()) + if Debug { + log.Print("Ignore kind: " + k.String()) + } } } @@ -90,7 +93,7 @@ func resolveField(value reflect.Value) { sf := p.Field(i) options := parseTag(sf.Tag.Get("ts")) - if err := changeField(value, field, options); err != nil { + if err := changeField(value, field, options); err != nil && Debug { log.Print(err) } diff --git a/tagsugar_test.go b/tagsugar_test.go index c5c481b..143924a 100644 --- a/tagsugar_test.go +++ b/tagsugar_test.go @@ -7,6 +7,7 @@ import ( func TestModel(t *testing.T) { Http = "https://cdn.github.com/" + Debug = true json := "{\"id\": 1, \"post\": 2}" array := "[{\"id\": 1, \"post\": 3},{\"id\": 2, \"post\": 66}]"