Recent Posts

Featured image for Golang Go Get Postgres Error

Golang Go Get Postgres Error

You are dealing with error handling in Go when working with PostgreSQL using the pq package. The code you provided demonstrates two different ways to handle and extract error information from a pq.Error type.

Let’s break down both of these code snippets:

  1. Using Type Assertion:
go
1
2
pqErr := err.(*pq.Error)
log.Println(pqErr.Code)

In this code, you are using a type assertion to check if the err is of type *pq.Error, and if it is, you extract the Code field from the pq.Error struct and log it. This approach assumes that err is a pq.Error type, and if it’s not, it will result in a runtime panic. So, it’s essential to be sure that err is indeed of type *pq.Error before using this approach.

Featured image for Bash Shell Ignore Error on particular Command

Bash Shell Ignore Error on particular Command

In Bash scripting, you can use the || true construct to ignore errors for a particular command or script. This is a common technique used to ensure that a script continues executing even if a specific command fails. Here’s how it works:

bash
1
particular_script || true

In this example, particular_script is the command or script that you want to run, and || true is added at the end of the command. The || operator is used for conditional execution. It means that if particular_script fails (returns a non-zero exit status), the true command will always execute, effectively ignoring the error and allowing the script to continue running.

Featured image for Delve Dlv Not Restart When Update Files On Golang Cosmtrek Air 12710…

Delve Dlv Not Restart When Update Files On Golang Cosmtrek Air 12710…

If you’re facing issues with Delve (dlv) not restarting when updating files in your Go project using Cosmtrek/Air version 1.27.10 and encountering a “port address already in use” error, there are a couple of solutions you can try. This problem often occurs due to lingering Delve processes that prevent the tool from restarting properly.

Solution 1: Revert to a Previous Version

You can revert to a previous version of Cosmtrek/Air where this issue might not exist. To do this, follow these steps:

Featured image for Bash Script to Get the Directory of the Script File

Bash Script to Get the Directory of the Script File

In Bash scripting, it’s often useful to determine the directory where the script file is located. This can be particularly important if your script needs to access other files or resources relative to its own location. Here’s a Bash script snippet that accomplishes this task:

bash
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash

# Get the directory of the script file
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)

# Check if SCRIPT_DIR is empty or not
if [ -z "$SCRIPT_DIR" ]; then
  echo "Failed to determine the script directory."
  exit 1
fi

# Now, you can use SCRIPT_DIR for your operations
echo "The script is located in the directory: $SCRIPT_DIR"

Here’s a breakdown of what this script does:

Featured image for Git Repository Naming

Git Repository Naming

This article explores best practices for naming Git repositories, ensuring clarity, consistency, and maintainability. It covers key considerations such as readability, versioning, project scope, and collaboration standards to help developers create effective repository names.

Microservices

Better suited to a project team or department where multiple products exist and are made up of sub-components.