index.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. ******************************************************************************
  3. * @file index.go
  4. * @author MakerYang
  5. ******************************************************************************
  6. */
  7. package StartWindows
  8. import (
  9. "cnc/framework/config"
  10. "context"
  11. "os"
  12. "runtime"
  13. "strings"
  14. )
  15. type Api struct {
  16. ctx context.Context
  17. }
  18. type ReturnResponse struct {
  19. Code int `json:"code"`
  20. Data interface{} `json:"data"`
  21. Msg string `json:"msg"`
  22. }
  23. func Init() *Api {
  24. return &Api{}
  25. }
  26. func (start *Api) Startup(ctx context.Context) {
  27. start.ctx = ctx
  28. }
  29. func (start *Api) Shutdown(ctx context.Context) {
  30. }
  31. func (start *Api) GetPlatform() string {
  32. platform := ""
  33. switch runtime.GOOS {
  34. case "windows":
  35. platform = "Windows"
  36. case "darwin":
  37. platform = "Darwin"
  38. case "linux":
  39. platform = "Linux"
  40. content, err := os.ReadFile("/etc/os-release")
  41. if err == nil {
  42. lines := strings.Split(string(content), "\n")
  43. for _, line := range lines {
  44. if strings.HasPrefix(line, "ID=") {
  45. switch {
  46. case strings.Contains(line, "ubuntu"):
  47. platform = "Ubuntu"
  48. case strings.Contains(line, "debian"):
  49. platform = "Debian"
  50. default:
  51. platform = "Linux"
  52. }
  53. }
  54. }
  55. }
  56. default:
  57. platform = "-"
  58. }
  59. return platform
  60. }
  61. func (start *Api) GetVersion() []string {
  62. return []string{Config.Get.Info.ProductName, Config.Get.Info.ProductVersion}
  63. }