You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, i want to get from server by interval time (like 1 second every cycle)
this is is my code
//@param nodeIDList []*ua.ReadValueID
for {
c := opcua.NewClient(opcServer, opcua.SecurityMode(ua.MessageSecurityModeNone))
if err := c.Connect(ctx); err != nil {
zap.L().Error("Connect to opc server failed:" + err.Error())
if c != nil {
c.CloseWithContext(ctx)
}
}
//defer c.CloseWithContext(ctx)
//defers in this infinite Loop will never run (SA5003) go-staticcheck
req := &ua.ReadRequest{
MaxAge: 2000,
NodesToRead: nodeIDList,
TimestampsToReturn: ua.TimestampsToReturnBoth,
}
var resp *ua.ReadResponse
var err error
resp, err = c.ReadWithContext(ctx, req)
if err != nil {
if c != nil {
c.CloseWithContext(ctx)
}
} else {
if resp == nil {
zap.L().Error("Received nil response from opc server")
} else {
result := resp.Results
for i, resultItem := range result {
// deal with the everything
}
}
if c != nil {
c.CloseWithContext(ctx)
}
}
time.Sleep(200 * time.Millisecond)
}
But go-staticcheck tell me defers in this infinite Loop will never run (SA5003) go-staticcheck, so i use
if c != nil {
c.CloseWithContext(ctx)
}
instead of this, could you give me some advice to do it?
I know use subscribe is good way, but i still learn it ...
The text was updated successfully, but these errors were encountered:
Hi, i want to get from server by interval time (like 1 second every cycle)
this is is my code
But go-staticcheck tell me
defers in this infinite Loop will never run (SA5003) go-staticcheck
, so i useinstead of this, could you give me some advice to do it?
I know use subscribe is good way, but i still learn it ...
The text was updated successfully, but these errors were encountered: