@@ -13,7 +13,6 @@ import (
1313
1414type sensitiveComponentImpl struct {
1515 checker rpc.ModerationSvcClient
16- enable bool
1716}
1817
1918type SensitiveComponent interface {
@@ -23,20 +22,16 @@ type SensitiveComponent interface {
2322}
2423
2524func NewSensitiveComponent (cfg * config.Config ) (SensitiveComponent , error ) {
26- c := & sensitiveComponentImpl {}
27- c .enable = cfg .SensitiveCheck .Enable
28-
29- if c .enable {
30- c .checker = rpc .NewModerationSvcHttpClient (fmt .Sprintf ("%s:%d" , cfg .Moderation .Host , cfg .Moderation .Port ))
25+ if ! cfg .SensitiveCheck .Enable {
26+ return & sensitiveComponentNoOpImpl {}, nil
3127 }
28+
29+ c := & sensitiveComponentImpl {}
30+ c .checker = rpc .NewModerationSvcHttpClient (fmt .Sprintf ("%s:%d" , cfg .Moderation .Host , cfg .Moderation .Port ))
3231 return c , nil
3332}
3433
35- func (c * sensitiveComponentImpl ) CheckText (ctx context.Context , scenario , text string ) (bool , error ) {
36- if ! c .enable {
37- return true , nil
38- }
39-
34+ func (c sensitiveComponentImpl ) CheckText (ctx context.Context , scenario , text string ) (bool , error ) {
4035 result , err := c .checker .PassTextCheck (ctx , scenario , text )
4136 if err != nil {
4237 return false , err
@@ -45,23 +40,15 @@ func (c *sensitiveComponentImpl) CheckText(ctx context.Context, scenario, text s
4540 return ! result .IsSensitive , nil
4641}
4742
48- func (c * sensitiveComponentImpl ) CheckImage (ctx context.Context , scenario , ossBucketName , ossObjectName string ) (bool , error ) {
49- if ! c .enable {
50- return true , nil
51- }
52-
43+ func (c sensitiveComponentImpl ) CheckImage (ctx context.Context , scenario , ossBucketName , ossObjectName string ) (bool , error ) {
5344 result , err := c .checker .PassImageCheck (ctx , scenario , ossBucketName , ossObjectName )
5445 if err != nil {
5546 return false , err
5647 }
5748 return ! result .IsSensitive , nil
5849}
5950
60- func (c * sensitiveComponentImpl ) CheckRequestV2 (ctx context.Context , req types.SensitiveRequestV2 ) (bool , error ) {
61- if ! c .enable {
62- return true , nil
63- }
64-
51+ func (c sensitiveComponentImpl ) CheckRequestV2 (ctx context.Context , req types.SensitiveRequestV2 ) (bool , error ) {
6552 fields := req .GetSensitiveFields ()
6653 for _ , field := range fields {
6754 if len (field .Value ()) == 0 {
@@ -79,3 +66,21 @@ func (c *sensitiveComponentImpl) CheckRequestV2(ctx context.Context, req types.S
7966 }
8067 return true , nil
8168}
69+
70+ // sensitiveComponentNoOpImpl this implementation provides a "no-op" (no operation) version of the SensitiveComponent interface,
71+ // where all methods simply return a "not sensitive" result without performing any actual checks.
72+ type sensitiveComponentNoOpImpl struct {
73+ }
74+
75+ func (c * sensitiveComponentNoOpImpl ) CheckText (ctx context.Context , scenario , text string ) (bool , error ) {
76+ return true , nil
77+ }
78+
79+ func (c * sensitiveComponentNoOpImpl ) CheckImage (ctx context.Context , scenario , ossBucketName , ossObjectName string ) (bool , error ) {
80+ return true , nil
81+ }
82+
83+ // implements SensitiveComponent
84+ func (c * sensitiveComponentNoOpImpl ) CheckRequestV2 (ctx context.Context , req types.SensitiveRequestV2 ) (bool , error ) {
85+ return true , nil
86+ }
0 commit comments