diff --git a/.dockerignore b/.dockerignore index 1339d33..ca5d543 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-03-02T13:41:04Z by kres latest. +# Generated on 2023-03-17T16:37:39Z by kres 6bde0cc. * !kmsg.go @@ -8,7 +8,8 @@ !message_test.go !reader.go !reader_test.go -!utils.go +!utils_bsd.go +!utils_linux.go !writer.go !writer_test.go !go.mod diff --git a/Dockerfile b/Dockerfile index edb2ac9..d04aa82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-03-02T13:41:04Z by kres latest. +# Generated on 2023-03-17T16:37:39Z by kres 6bde0cc. ARG TOOLCHAIN @@ -55,7 +55,8 @@ COPY ./message.go ./message.go COPY ./message_test.go ./message_test.go COPY ./reader.go ./reader.go COPY ./reader_test.go ./reader_test.go -COPY ./utils.go ./utils.go +COPY ./utils_bsd.go ./utils_bsd.go +COPY ./utils_linux.go ./utils_linux.go COPY ./writer.go ./writer.go COPY ./writer_test.go ./writer_test.go RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null diff --git a/Makefile b/Makefile index 2910a99..8995ab4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-03-02T13:41:04Z by kres latest. +# Generated on 2023-03-17T16:37:39Z by kres 6bde0cc. # common variables @@ -16,10 +16,10 @@ REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) GOLANGCILINT_VERSION ?= v1.51.2 GOFUMPT_VERSION ?= v0.4.0 GO_VERSION ?= 1.20 -GOIMPORTS_VERSION ?= v0.6.0 +GOIMPORTS_VERSION ?= v0.7.0 PROTOBUF_GO_VERSION ?= 1.28.1 -GRPC_GO_VERSION ?= 1.2.0 -GRPC_GATEWAY_VERSION ?= 2.15.1 +GRPC_GO_VERSION ?= 1.3.0 +GRPC_GATEWAY_VERSION ?= 2.15.2 VTPROTOBUF_VERSION ?= 0.4.0 DEEPCOPY_VERSION ?= v0.5.5 GO_BUILDFLAGS ?= diff --git a/utils_bsd.go b/utils_bsd.go new file mode 100644 index 0000000..5a9bd86 --- /dev/null +++ b/utils_bsd.go @@ -0,0 +1,23 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +//go:build darwin || dragonfly || freebsd || netbsd || openbsd + +package kmsg + +import ( + "fmt" + "time" + + "golang.org/x/sys/unix" +) + +func getBootTime() (time.Time, error) { + timeval, err := unix.SysctlTimeval("kern.boottime") + if err != nil { + return time.Time{}, fmt.Errorf("could not get boot time: %w", err) + } + + return time.Unix(timeval.Unix()), nil +} diff --git a/utils.go b/utils_linux.go similarity index 82% rename from utils.go rename to utils_linux.go index 8c1aa3a..db3aec0 100644 --- a/utils.go +++ b/utils_linux.go @@ -2,18 +2,21 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +//go:build linux + package kmsg import ( "fmt" - "syscall" "time" + + "golang.org/x/sys/unix" ) func getBootTime() (time.Time, error) { - var sysinfo syscall.Sysinfo_t + var sysinfo unix.Sysinfo_t - err := syscall.Sysinfo(&sysinfo) + err := unix.Sysinfo(&sysinfo) if err != nil { return time.Time{}, fmt.Errorf("could not get boot time: %w", err) }