Posts

Go Language, MYSQL - Simple Rest CRUD API example

Image
In this article, we will show you how to develop a  REST-style web service with Go Language and MYSQL. These are APIs that Spring backend App will export: GET all User's        :   /users GET User by ID     :   /users/{id}  POST User             :   /users PUT User               :   /users DELETE User       :   /users/{id} Technologies used: Go Language MYSQL Database gorilla/mux jinzhu/gorm gorilla/mux:  The gorilla/mux package provides request routing, validation, and other services. jinzhu/gorm:  The gorm is an ORM library for the Go language.GORM provides CRUD operations and can also be used for the initial migration and creation of the database schema. Final Project Structure: Let's start building the application Create database 'userdb': CREATE DATABASE userdb; Initialize the Go project: Initialize the Go project  using the following command go mod init rest-crud-api-go-lang Adding the modules required for the project: go get github.com/gorilla/mux go get github.c

Implement functional interfaces using lambda expressions

Image
Java is Object Oriented Programming language , being object-oriented is not bad, but it brings a lot of verbosity to the program. Java 8 introduced new libraries and programming styles, for example,  functional interfaces ,  lambda expressions , and streams . These bring functional-style programming to the object-oriented programming capabilities of Java. Java Functional Interface and Lambda Expression help us in writing smaller and cleaner code by removing a lot of boilerplate code. Java Functional Interface: A functional interface in Java is an interface that contains only a single abstract method.  A functional interface can contain default and static methods which do have an implementation, in addition to the single unimplemented method. Here is a Java functional interface examples: Example 1, The below counts as a functional interface in Java because it only contains a single method, and that method has no implementation: public interface Addition { public Integer calcula

How to add/subtract Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to a date in Go Language

Image
Hello everyone, In this tutorial, we will learn h ow to add/subtract Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to date in Go Language. The time package in Go language provides Add() function which  is used to add/subtract a duration to time t. Since duration can be represented in hours, minutes, seconds, milliseconds, microseconds and nanoseconds, The signature of the Add method is: func (t Time) Add(d Duration) Time Example 1: Go Program to add/subtract minutes. package main import ( "fmt" "time" ) func main() { //Current date and time dt1 := time.Now() fmt.Println( "Current date and time : " , dt1) //Adding 30 minutes dt2 := dt1.Add( 30 * time.Minute) fmt.Println( "After 30 minutes:" , dt2) //Subtract 3 minutes dt3 := dt1.Add(- 3 * time.Minute) fmt.Println( "Before 3 minutes:" , dt3) } Output: Example 2: Go Program to add/subtract seconds. package main import (