tgo() {
  tgo_path="${HOME}/.tmp/tgo"
  mkdir -p "${tgo_path}"

  # check if the first argument is exists
  if [ -n "${1}" ]; then
    # shellcheck disable=SC2312
    tmp="$(mktemp -p "${tgo_path}" -d "${1}_$(date +%Y%m%d)_XXXXXXXX")"
    (
        cd "${tmp}" || return
        go mod init "$(basename "${tmp}")"
        cat > "main.go" << EOF
package main

func main() {
}
EOF

            cat > "main_test.go" << EOF
package main_test

import (
	"os"
	"testing"
)

func TestMain(m *testing.M) {
	os.Exit(m.Run())
}

func BenchmarkMain(b *testing.B) {
	b.ReportAllocs()
	for n := 0; n < b.N; n++ {

	}
}
EOF

        nvim -p main.go main_test.go
        echo "${tmp}"
      )
    else
      choice=$(find "${tgo_path}" -maxdepth 1 -type d -exec basename {} \; | fzf) && \
          (cd "${tgo_path}/${choice}" && \
          nvim -p main.go main_test.go)
  fi
}
