utils.go 453 B

12345678910111213141516171819202122232425262728
  1. package utils
  2. import (
  3. "log"
  4. "os"
  5. "runtime"
  6. "strconv"
  7. "strings"
  8. )
  9. func Cwd(i int) string {
  10. _, fp, _, _ := runtime.Caller(i)
  11. slice := strings.Split(fp, "/")
  12. slice = slice[:len(slice)-1]
  13. path := strings.Join(slice, "/")
  14. return path
  15. }
  16. func CheckArgs() {
  17. if len(os.Args) < 2 {
  18. log.Fatalf("ERROR: port number required: eg ./bin 3000")
  19. }
  20. _, err := strconv.Atoi(os.Args[1])
  21. if err != nil {
  22. log.Fatalf("ERROR: port must be a number")
  23. }
  24. }