diff --git a/internal/server/scripts.go b/internal/server/scripts.go index 5f781f80..0956f224 100644 --- a/internal/server/scripts.go +++ b/internal/server/scripts.go @@ -27,7 +27,7 @@ const ( ) // For Lua os.clock() impl -var startedAt time.Time +var startedAt time.Time = time.Now() var errShaNotFound = errors.New("sha not found") var errCmdNotSupported = errors.New("command not supported in scripts") @@ -45,10 +45,6 @@ type lStatePool struct { total int } -func init() { - startedAt = time.Now() -} - // newPool returns a new pool of lua states func (s *Server) newPool() *lStatePool { pl := &lStatePool{ @@ -913,7 +909,7 @@ func baseToNumber(L *lua.LState) int { L.Push(lv) case lua.LString: str := strings.Trim(string(lv), " \n\t") - if strings.Index(str, ".") > -1 { + if strings.Contains(str, ".") { if v, err := strconv.ParseFloat(str, lua.LNumberBit); err != nil { L.Push(lua.LNil) } else { @@ -944,7 +940,7 @@ func baseToString(L *lua.LState) int { // Lua os.clock() func osClock(L *lua.LState) int { - L.Push(lua.LNumber(float64(time.Now().Sub(startedAt)) / float64(time.Second))) + L.Push(lua.LNumber(time.Since(startedAt).Seconds())) return 1 }