Skip to content

Commit

Permalink
feat: add BSD support
Browse files Browse the repository at this point in the history
In addition, this commit replaces the syscal package, which is
deprecated, by golang.org/x/sys/unix.

Signed-off-by: Hervé Werner <dud225@hotmail.com>
Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
dud225 authored and smira committed Mar 17, 2023
1 parent 7a51094 commit 4297bd5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .dockerignore
@@ -1,14 +1,15 @@
# 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
!message.go
!message_test.go
!reader.go
!reader_test.go
!utils.go
!utils_bsd.go
!utils_linux.go
!writer.go
!writer_test.go
!go.mod
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions 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

Expand All @@ -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 ?=
Expand Down
23 changes: 23 additions & 0 deletions 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
}
9 changes: 6 additions & 3 deletions utils.go → utils_linux.go
Expand Up @@ -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)
}
Expand Down

0 comments on commit 4297bd5

Please sign in to comment.