Remove non-crossplatform syscalls from /api/about.

The only way to get precise OS information cross platform is to have
a separate file for each platform with a build tag that returns the
info, which seems excessive for this usecase.
This commit is contained in:
Kailash Nadh 2023-08-06 10:49:12 +05:30
parent a1c507b477
commit 104c4fc993
3 changed files with 13 additions and 22 deletions

View file

@ -701,24 +701,22 @@ func initBounceManager(app *App) *bounce.Manager {
func initAbout(q *models.Queries, db *sqlx.DB) about {
var (
mem runtime.MemStats
utsname syscall.Utsname
mem runtime.MemStats
)
// Memory / alloc stats.
runtime.ReadMemStats(&mem)
// OS info.
if err := syscall.Uname(&utsname); err != nil {
lo.Printf("WARNING: error getting system info: %v", err)
}
// DB dbv.
info := types.JSONText(`{}`)
if err := db.QueryRow(q.GetDBInfo).Scan(&info); err != nil {
lo.Printf("WARNING: error getting database version: %v", err)
}
hostname, err := os.Hostname()
if err != nil {
lo.Printf("WARNING: error getting hostname: %v", err)
}
return about{
Version: versionString,
Build: buildString,
@ -729,10 +727,9 @@ func initAbout(q *models.Queries, db *sqlx.DB) about {
NumCPU: runtime.NumCPU(),
},
Host: aboutHost{
OS: int8ToStr(utsname.Sysname[:]),
OSRelease: int8ToStr(utsname.Release[:]),
Machine: int8ToStr(utsname.Machine[:]),
Hostname: int8ToStr(utsname.Nodename[:]),
OS: runtime.GOOS,
Machine: runtime.GOARCH,
Hostname: hostname,
},
}

View file

@ -24,10 +24,9 @@ import (
const pwdMask = "•"
type aboutHost struct {
OS string `json:"os"`
OSRelease string `json:"os_release"`
Machine string `json:"arch"`
Hostname string `json:"hostname"`
OS string `json:"os"`
Machine string `json:"arch"`
Hostname string `json:"hostname"`
}
type aboutSystem struct {
NumCPU int `json:"num_cpu"`

View file

@ -101,11 +101,6 @@ func strSliceContains(str string, sl []string) bool {
return false
}
func int8ToStr(bs []int8) string {
b := make([]byte, len(bs))
for i, v := range bs {
b[i] = byte(v)
}
func trimNullBytes(b []byte) string {
return string(bytes.Trim(b, "\x00"))
}