# Instructions: Setup Go Version 1.24.0, Manage Dependencies, Build, and Run

## Prerequisites

Before proceeding, make sure you have the following installed on your computer:

- **Go (Golang) version 1.24.0**
- **Make**

## Steps to Install Go 1.24.0

### `go` For Windows:

1. Download the installer from [official Go website](https://golang.org/dl/).
2. Run the downloaded `.msi` file and follow the installation wizard.
3. During installation, you may be prompted to set the `GOPATH` and `GOROOT`. Choose the appropriate settings
based on your preference or keep the default values.

### `go` For macOS:

1. Open Terminal.
2. Download the package using Homebrew (if not installed, visit [Homebrew website](https://brew.sh/) for
installation instructions):

   ```bash
   brew install go@1.24
   ```

3. Link the installed version to your PATH:

   ```bash
   brew link --overwrite --force go@1.24
   ```

### `go` For Linux:

1. Open Terminal.
2. Download the appropriate tarball from [official Go website](https://golang.org/dl/).
3. Extract the downloaded archive:

   ```bash
   tar -C /usr/local -xzf go1.24.linux-amd64.tar.gz
   ```

4. Add Go to your PATH by editing your shell configuration file (e.g., `.bashrc`, `.zshrc`):

   ```bash
   echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bashrc
   source ~/.bashrc
   ```

## Verify Installation

After installation, verify that Go 1.24.0 is installed correctly by running:

```bash
go version
```

You should see an output like `go version go1.24 darwin/amd64` (or similar, depending on your OS).

## Install Make (if not already installed)

### `make` For Windows:

- Download and install [Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm).
- Add the installation directory to your PATH.

### `make` For macOS:

1. Open Terminal.
2. Install Make using Homebrew:

   ```bash
   brew install make
   ```

### `make` For Linux:

Make is usually pre-installed on most Linux distributions. If it's not installed, you can install it using your
package manager (e.g., `sudo apt-get install make` for Ubuntu).

## Navigate to Your Go Project Directory

Open Terminal and navigate to the root directory of your Go project.

## Resolve Dependencies with `go mod tidy`

Run the following command to download and resolve all dependencies specified in your `go.mod` file:

```bash
go mod tidy
```

## Setup Database

In your Go application, you'll need to set the following environment variables to connect to your database:

```bash
DB_HOST: The hostname or IP address of your database server (e.g., localhost, 127.0.0.1, or the actual DB server URL).
DB_USER: The username for your database connection.
DB_PASSWORD: The password associated with the DB_USER.
DB_NAME: The name of the database you want to connect to.
DB_PORT: The port number your database server is running on (default MySQL port is 3306, default PostgreSQL port is 5432).
```

## Create `.env` File

It's best practice to keep sensitive information like database credentials in an environment file. Create or edit the .env file in the root directory of your project and add the following lines:

```bash
DB_HOST=localhost
DB_USER=your_db_user
DB_PASSWORD=your_db_password
DB_NAME=your_db_name
DB_PORT=3306 # or 5432, depending on your DB type

APP_PORT=3000 # example
GRACEFULL_TIMEOUT=10 #example
SALT_SECURITY=your_secret_security

Make sure to replace the values with your actual database details.
```

## Migrate the Database Using `make migrate`

Before running your application, let's setup your database first.

```bash
make migrate
```

## Build the Binary Using `make build`

Run the following command to build your project. The binary will be placed in the `bin` folder.

```bash
make build
```

## Run the Program Using `make run`

Finally, you can run your program using:

```bash
make run
```

This command will compile and execute your Go application.

Or you can execute the compiled binary at `bin/legalgo` by:

```bash
./bin/legalgo
```

---

**Note:** Ensure that your `Makefile` is correctly set up to handle these commands. If not, you may need to create
or adjust it accordingly.

```

Please follow the above instructions to set up Go version 1.24.0, manage dependencies using `go mod tidy`, build a
binary with `make build`, and run your application with `make run`.
