Skip to content

Allow compiling and running the project on macOS and windows #1421

@gabriel-vasile

Description

@gabriel-vasile

Hi, I'm trying to run the project locally, on macos, and I'm having trouble.

To reproduce my problem, you can try compiling the project for macos/windows:

# GOOS=darwin GOARCH=arm64 go build cmd/*.go
GOOS=windows GOARCH=amd64 go build cmd/*.go

cmd/init.go:705:19: undefined: syscall.Utsname
cmd/init.go:712:20: undefined: syscall.Uname
cmd/settings.go:302:19: undefined: syscall.Utsname
cmd/settings.go:307:20: undefined: syscall.Uname

uname syscall is only available for linux in golang. This code does not compile on macos/windows:

listmonk/cmd/init.go

Lines 703 to 714 in a440b79

var (
mem runtime.MemStats
utsname syscall.Utsname
)
// Memory / alloc stats.
runtime.ReadMemStats(&mem)
// OS info.
if err := syscall.Uname(&utsname); err != nil {
lo.Printf("WARNING: error getting system info: %v", err)
}

A more portable way to write that bit of code is to use Utsname and Uname from the golang.org/x/sys/unix package, but that does not work for windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions