mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
refactor: move parsing into internal/parse module, move other functions into misc
This commit is contained in:
26
internal/misc.go
Normal file
26
internal/misc.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type EnabledDisabledInfo struct {
|
||||
Entity string
|
||||
State string
|
||||
RunOnError bool
|
||||
}
|
||||
|
||||
var (
|
||||
id atomic.Int64 // default value is 0
|
||||
)
|
||||
|
||||
func GetId() int64 {
|
||||
return id.Add(1)
|
||||
}
|
||||
|
||||
// GetFunctionName returns the name of the function that the interface is a pointer to.
|
||||
func GetFunctionName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
@@ -1,30 +1,13 @@
|
||||
package internal
|
||||
package parse
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/golang-module/carbon"
|
||||
)
|
||||
|
||||
type EnabledDisabledInfo struct {
|
||||
Entity string
|
||||
State string
|
||||
RunOnError bool
|
||||
}
|
||||
|
||||
var (
|
||||
id atomic.Int64 // default value is 0
|
||||
)
|
||||
|
||||
func GetId() int64 {
|
||||
return id.Add(1)
|
||||
}
|
||||
|
||||
// Parses a HH:MM string.
|
||||
func ParseTime(s string) carbon.Carbon {
|
||||
t, err := time.Parse("15:04", s)
|
||||
@@ -45,7 +28,3 @@ func ParseDuration(s string) time.Duration {
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func GetFunctionName(i interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
|
||||
}
|
||||
Reference in New Issue
Block a user