package main import ( "fmt" "os" ) func main() { file, err := os.Open("example.txt") if err != nil { fmt.Println("Error: ", err) return } defer file.Close() // rest of the code }
package main import ( "fmt" "os" ) func main() { err := os.Mkdir("new_dir", 0755) if err != nil { fmt.Println("Error: ", err) return } // rest of the code }In this example, we use the os package's Mkdir function to create a new directory named "new_dir". If there is an error during the creation process, such as if the directory already exists or if the user does not have the necessary permissions to create the directory, the os package will return an error object. We then use a conditional statement to check if the error object is not nil. If it is not nil, we print the error message. The package library for these examples is the os package.