Skip to content

Commit

Permalink
build on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
korovindenis committed Jun 12, 2023
1 parent 6e7fd75 commit cf99bdf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 72 deletions.
36 changes: 35 additions & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package service

import "time"
import (
"log"
"time"
)

type Status struct {
Mode string
Expand All @@ -14,6 +17,37 @@ type countdown struct {
s int
}

func New(s *Status, logslevel uint) {
for {
if s.Mode == "" {
time.Sleep(time.Second * 5)
} else {
time.Sleep(1 * time.Second)
v, _ := time.Parse(time.RFC3339, s.TimeShutDown)
timeRemaining := getTimeRemaining(v)

if s.Mode != "" {
if timeRemaining.t <= 0 {
// bye
if logslevel > 0 {
log.Println("Run:", s.Mode)
}
callMode := syscall.LINUX_REBOOT_CMD_POWER_OFF

Check failure on line 35 in internal/service/service.go

View workflow job for this annotation

GitHub Actions / lint

undeclared name: `syscall` (typecheck)
if s.Mode == "reboot" {
callMode = syscall.LINUX_REBOOT_CMD_RESTART

Check failure on line 37 in internal/service/service.go

View workflow job for this annotation

GitHub Actions / lint

undeclared name: `syscall` (typecheck)
}
err := syscall.Reboot(callMode)

Check failure on line 39 in internal/service/service.go

View workflow job for this annotation

GitHub Actions / lint

undeclared name: `syscall` (typecheck)
if err != nil {
log.Fatalf("%s", err)
}
} else if logslevel > 1 {
log.Printf("Time for %s - %d:%d:%d\n", s.Mode, timeRemaining.h, timeRemaining.m, timeRemaining.s)
}
}
}
}
}

func getTimeRemaining(t time.Time) countdown {
currentTime := time.Now().UTC()
difference := t.Sub(currentTime)
Expand Down
38 changes: 0 additions & 38 deletions internal/service/service_linux.go

This file was deleted.

33 changes: 0 additions & 33 deletions internal/service/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package service

import (
"fmt"
"log"
"time"
)

var syscall Syscall
Expand All @@ -22,34 +20,3 @@ func (s Syscall) Reboot(mode byte) error {

return nil
}

func New(s *Status, logslevel uint) {
for {
if s.Mode == "" {
time.Sleep(time.Second * 5)
} else {
time.Sleep(1 * time.Second)
v, _ := time.Parse(time.RFC3339, s.TimeShutDown)
timeRemaining := getTimeRemaining(v)

if s.Mode != "" {
if timeRemaining.t <= 0 {
// bye
if logslevel > 0 {
log.Println("Run:", s.Mode)
}
callMode := syscall.LINUX_REBOOT_CMD_POWER_OFF
if s.Mode == "reboot" {
callMode = syscall.LINUX_REBOOT_CMD_RESTART
}
err := syscall.Reboot(callMode)
if err != nil {
log.Fatalf("%s", err)
}
} else if logslevel > 1 {
log.Printf("Time for %s - %d:%d:%d\n", s.Mode, timeRemaining.h, timeRemaining.m, timeRemaining.s)
}
}
}
}
}

0 comments on commit cf99bdf

Please sign in to comment.