export.go 842 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2025 BackendServerTemplate Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package osutils
  5. import (
  6. "os"
  7. "path/filepath"
  8. "strings"
  9. )
  10. var _args0 = ""
  11. var _args0Name = ""
  12. var _args0NamePosix = ""
  13. func init() {
  14. var err error
  15. _args0, err = os.Executable()
  16. if err != nil {
  17. if len(os.Args) > 0 {
  18. _args0 = os.Args[0]
  19. } else {
  20. panic(err)
  21. }
  22. }
  23. if _args0 == "" {
  24. panic("_args0 was empty")
  25. }
  26. _args0Name = filepath.Base(_args0)
  27. if _args0Name == "" {
  28. panic("_args0Name was empty")
  29. }
  30. _args0NamePosix = strings.TrimSuffix(_args0Name, ".exe")
  31. if _args0NamePosix == "" {
  32. panic("_args0NamePosix was empty")
  33. }
  34. }
  35. func GetArgs0() string {
  36. return _args0
  37. }
  38. func GetArgs0Name() string {
  39. return filepath.Base(_args0Name)
  40. }