Tag Archives: Lang

How to create a connection to Database using go lang | by Achmad Fatoni | Jan, 2024

In the steps above we have created a database and table that we will use to connect using Go Lang. The next step is to create a service and configure it to connect to the database that was created previously. Here are the steps:

1. First initiate our project using the following command:

go mod init [nama project]

# example
go mod init test-connection-db

2. Because here I am using MySQL as the database, here we need to add the MySQL driver package.

go get github.com/go-sql-driver/mysql

3. Next, we setup the database connection by creating a new file called connection/database.go. Paste the following code :

package connection

import (
"database/sql"
"time"

_ "github.com/go-sql-driver/mysql"
)

func GetConnection() *sql.DB {
// username = root
// password = admin
// host = 127.0.0.1
// db name =...


Source link

How to install and run simple applications in Go Lang | by Achmad Fatoni | Dec, 2023

source : go.dev

Hi all..!!
After not writing an article for more than 2 months, here I will share something new that I learned, namely go lang. in this article I will share how to install and run the simple go lang application.

Go is an open source programming language that is supported by Google and many companies use this language in creating their backend applications. Several large companies use this language in their applications, namely Google, Paypal, American Express, Bitly, Netflix, and many more.

The Go Lang language was first released in November 2009 and in 2020 the Go language started to become quite well known for its fairly easy use, flexibility and fast performance. The go language compiles the code that we have created into machine language so that this can make Go execute…


Source link