mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 13:15:14 -06:00
refactor: use atomic.Int64 for underlying GetId implementation
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/golang-module/carbon"
|
"github.com/golang-module/carbon"
|
||||||
@@ -16,11 +17,12 @@ type EnabledDisabledInfo struct {
|
|||||||
RunOnError bool
|
RunOnError bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var id int64 = 0
|
var (
|
||||||
|
id atomic.Int64 // default value is 0
|
||||||
|
)
|
||||||
|
|
||||||
func GetId() int64 {
|
func GetId() int64 {
|
||||||
id += 1
|
return id.Add(1)
|
||||||
return id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses a HH:MM string.
|
// Parses a HH:MM string.
|
||||||
|
|||||||
Reference in New Issue
Block a user