Use Redis With Golang

Using Golang and Redis Redis is an in-memory data structure store that can be used as a database, cache, and message broker. It is known for its speed, simplicity, and flexibility. In this article, we will discuss how to use Redis with Golang, a popular programming language known for its simplicity, performance, and concurrency support. Before we dive into the details of using Redis with Golang, let’s first understand the requirements of the application. ...

December 19, 2022 · 7 min · 1488 words

Create Desktop Application to fetch Stock Market Data with Golang

Golang, also known as Go, is a popular programming language known for its simplicity, performance, and concurrency support. Fyne is an open-source cross-platform UI toolkit written in Go, which makes it an excellent choice for building desktop applications. In this article, we will discuss how to build a desktop application for stock market data using Golang and Fyne. Before we dive into the details of building the application, let’s first understand the requirements of the application. ...

December 19, 2022 · 4 min · 734 words

Work with Json field on Postgresql

In PostgreSQL, the json data type can be used to store JSON data. You can use the -> operator to access elements of a JSON object, and the -» operator to access values of a JSON object as text. For example, consider the following table with a JSON field called data: CREATE TABLE documents ( id serial PRIMARY KEY, data json ); To insert a JSON object into the data field, you can use the json_build_object function: ...

December 19, 2022 · 1 min · 198 words

How to Create a Webserver in Golang

To create a web server in Go, you can use the http package provided by the standard library. This package includes the http.Server type, which represents an HTTP server, and the http.ListenAndServe() function, which listens for incoming HTTP requests on a specified port and serves responses to those requests. Here is an example of how you might create a simple web server in Go: // Import the http package import "net/http" // Define a function that will be called to handle incoming HTTP requests func handler(w http.ResponseWriter, r *http.Request) { // Write a response message to the client fmt.Fprintf(w, "Hello, World!") } func main() { // Set up a route that will call the handler function for any requests to the root URL http.HandleFunc("/", handler) // Start the web server and listen for incoming requests on port 8080 http.ListenAndServe(":8080", nil) } In this example, the handler() function is defined to handle incoming HTTP requests. This function receives a http.ResponseWriter and a *http.Request as arguments, which are used to write the response message and access information about the incoming request, respectively. The main() function sets up a route that will call the handler() function for any requests to the root URL ("/") and then starts the web server using the http.ListenAndServe() function. This web server will listen for incoming requests on port 8080 and serve responses using the handler() function. ...

December 11, 2022 · 4 min · 753 words

How to Use Interfaces in Golang

In Go, an interface is a type that defines a set of methods that a struct must implement in order to implement the interface. An interface defines the behavior or capabilities of a struct without specifying the implementation details. This allows different structs to implement the same interface in different ways, promoting loose coupling and flexibility in your code. Here is an example of an interface in Go: // Define an interface named Animal type Animal interface { // Define a method named Speak that takes no arguments and returns a string Speak() string } In this example, the Animal interface defines a single method named Speak(), which takes no arguments and returns a string. Any struct that wants to implement the Animal interface must implement this Speak() method. ...

December 11, 2022 · 2 min · 253 words