Skip to content

Commit 7a1faf2

Browse files
cuiweixiematthewmcneely
authored andcommitted
refactor(audit): using atomic type atomic.Uint32
1 parent 5d6928f commit 7a1faf2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

audit/audit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
NodeTypeZero = "zero"
2525
)
2626

27-
var auditEnabled uint32
27+
var auditEnabled atomic.Uint32
2828

2929
type AuditEvent struct {
3030
User string
@@ -107,7 +107,7 @@ func InitAuditor(conf *x.LoggerConf, gId, nId uint64) error {
107107
if auditor.log, err = x.InitLogger(conf, filename); err != nil {
108108
return err
109109
}
110-
atomic.StoreUint32(&auditEnabled, 1)
110+
auditEnabled.Store(1)
111111
glog.Infoln("audit logs are enabled")
112112
return nil
113113
}
@@ -116,7 +116,7 @@ func InitAuditor(conf *x.LoggerConf, gId, nId uint64) error {
116116
// It also sets the log to nil, because its being called by zero when license expires.
117117
// If license added, InitLogger will take care of the file.
118118
func Close() {
119-
if atomic.LoadUint32(&auditEnabled) == 0 {
119+
if auditEnabled.Load() == 0 {
120120
return
121121
}
122122
auditor.log.Sync()

audit/interceptor.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func AuditRequestGRPC(ctx context.Context, req interface{},
6868
return skipApis[info.FullMethod[strings.LastIndex(info.FullMethod, "/")+1:]]
6969
}
7070

71-
if atomic.LoadUint32(&auditEnabled) == 0 || skip(info.FullMethod) {
71+
if auditEnabled.Load() == 0 || skip(info.FullMethod) {
7272
return handler(ctx, req)
7373
}
7474
response, err := handler(ctx, req)
@@ -82,7 +82,7 @@ func AuditRequestHttp(next http.Handler) http.Handler {
8282
return skipEPs[r.URL.Path]
8383
}
8484

85-
if atomic.LoadUint32(&auditEnabled) == 0 || skip(r.URL.Path) {
85+
if auditEnabled.Load() == 0 || skip(r.URL.Path) {
8686
next.ServeHTTP(w, r)
8787
return
8888
}
@@ -110,7 +110,7 @@ func AuditRequestHttp(next http.Handler) http.Handler {
110110
}
111111

112112
func AuditWebSockets(ctx context.Context, req *schema.Request) {
113-
if atomic.LoadUint32(&auditEnabled) == 0 {
113+
if auditEnabled.Load() == 0 {
114114
return
115115
}
116116

0 commit comments

Comments
 (0)