<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rahul Gubiligari on Medium]]></title>
        <description><![CDATA[Stories by Rahul Gubiligari on Medium]]></description>
        <link>https://medium.com/@roystatham3003?source=rss-0b5a88ca9382------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ScCaXxcorOfUj0U3w8sFWQ.jpeg</url>
            <title>Stories by Rahul Gubiligari on Medium</title>
            <link>https://medium.com/@roystatham3003?source=rss-0b5a88ca9382------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 06:16:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@roystatham3003/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to set up a Basic Node js App]]></title>
            <link>https://medium.com/@roystatham3003/how-to-set-up-a-basic-node-js-app-fe839552ff9c?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe839552ff9c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Mon, 03 Jun 2024 10:45:01 GMT</pubDate>
            <atom:updated>2024-06-03T10:45:01.623Z</atom:updated>
            <content:encoded><![CDATA[<p>Steps:</p><ol><li>Create an empty folder on your computer.</li><li>Open Vs Code and go to your folder.</li><li>Run the following command: “npm init -y”</li><li>This command will initialize a node js app in that folder by creating the package.json file.</li><li>Then, install your required dependencies by running the following command: “npm install &lt;package-name&gt;”</li><li>Ex: npm install express, npm install nodemon</li><li><strong><em>Nodemon</em></strong> is a utility that monitors for any changes in your source code and automatically restarts your server. It is particularly useful during development because it saves you from having to manually restart your server every time you make changes to your code.</li><li>You can edit the package.json file to accomodate the automatic startup using nodemon.</li><li>Use the following vanilla package.json with nodemon to create a basic Node js server.</li><li>Now, you can create an index.js file in the same folder and then write some code like a console statement and run the following command to start the node js server: “npm run dev”</li></ol><pre>{<br>  &quot;name&quot;: &quot;backend&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Real Time Data Processing node js app&quot;,<br>  &quot;type&quot;: &quot;module&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;node index.js&quot;,<br>    &quot;dev&quot;: &quot;nodemon index.js&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe839552ff9c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MERN Stack: Connecting to MongoDB from a Node.js application]]></title>
            <link>https://medium.com/@roystatham3003/mern-stack-connecting-to-mongodb-from-a-node-js-application-813329fb6ecf?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/813329fb6ecf</guid>
            <category><![CDATA[mongo]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Wed, 15 May 2024 04:35:54 GMT</pubDate>
            <atom:updated>2024-05-15T21:53:30.693Z</atom:updated>
            <content:encoded><![CDATA[<p>MERN: MongoDB, Express.js, React, Nodejs</p><p>MERN stack refers to the technologies required to build a Full-Stack application.</p><p>In this article, we are going to discuss two of the technologies:</p><p>NodeJs and MongoDB.</p><p>NodeJs is JS runtime environment (basically serves as Backend in the MERN web application).</p><p>MongoDB is the NoSql DB we are going to connect.</p><p>Prerequisites:</p><ol><li>Docker</li><li>Node Js</li><li>Mongo DB</li></ol><p>Steps:</p><ol><li>Pull the Mongo DB docker image -&gt; <em>docker pull mongo:6</em></li><li>Setup the docker-compose.yml file.</li><li>Run the docker-compose file to create the Docker container.</li><li>Use mongosh (Mongo Shell) to interact with MongoDB.</li></ol><p><em>docker-compose.yml</em></p><pre>version: &#39;3.1&#39;<br><br>services:<br><br>  mongo:<br>    image: mongo:6<br>    container_name: mongo-mern<br>    restart: always<br>    ports:<br>      - &quot;27017:27017&quot;<br>    environment:<br>      MONGO_INITDB_ROOT_USERNAME: root<br>      MONGO_INITDB_ROOT_PASSWORD: root<br>      MONGO_INITDB_DATABASE: bookstore-mern</pre><p>After the docker container gets created, run this following command to use the Mongo Shell to interact with Mongo DB :</p><p>The structure:</p><p>docker exec -it &lt;container-name&gt; mongosh -U &lt;user&gt; -d &lt;db-name&gt;</p><pre>docker exec -it mongo-mern mongosh -U root -d bookstore-mern </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oc5s8Gt_ODmcDNs-TYmWRA.png" /></figure><p>The Mongo shell opens up like this and then you can create your DB using the “use &lt;db-name&gt;” command.</p><p>You can also create a DB user of your own and give the necessary permissions:</p><p>Command to create a DB user:</p><pre> db.createUser({ user: &quot;mongo-mern-user&quot;, pwd: &quot;root&quot;, roles: [ { role: &quot;readWrite&quot;, db: &quot;bookstore-mern&quot; }] })</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8qIpowKhslkDQc_ZDPqRAQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=813329fb6ecf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Steps to connect to PostgreSQL Database using Docker]]></title>
            <link>https://medium.com/@roystatham3003/steps-to-connect-to-postgres-database-using-docker-a66143db9d9a?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/a66143db9d9a</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Tue, 14 May 2024 09:25:15 GMT</pubDate>
            <atom:updated>2024-05-14T09:26:37.145Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*F_kCwxV7KKFeMYNReBinag.png" /></figure><p>Here are the simple steps to connect to a Postgres DB using Docker.</p><p>We are going to use <em>docker-compose</em> to configure the DB connection.</p><p>This is the d<em>ocker-compose.yml</em> file used to connect to the Postgres DB:</p><p><em>docker-compose.yml</em></p><pre>version: &#39;3&#39;<br>services:<br>  postgres:<br>    image: postgres:latest<br>    container_name: postgres-jwt-auth<br>    ports:<br>      - &quot;5432:5432&quot;<br>    environment:<br>      POSTGRES_USER: &quot;postgres&quot;<br>      POSTGRES_PASSWORD: &quot;postgres&quot;<br>      POSTGRES_DB: postgres-jwt</pre><p>In this .yml file, we are defining the environment variables needed to establish a connection to the Postgres DB.</p><p>The env variables used are:</p><ol><li>User</li><li>Password</li><li>DB name</li></ol><pre>POSTGRES_USER<br>POSTGRES_PASSWORD<br>POSTGRES_DB</pre><p>The default port for postgres is “5432”</p><p>We need to specify the docker image as well in the image section of the .yml file.</p><p>We have specified “postgres:latest” which means the latest docker image for postgres is pulled from DockerHub and run in the docker container.</p><p>We can also specify the optional container-name.</p><p>That’s it. This is all we need to configure to run Postgres on Docker.</p><p>Now, we need to trigger the below command to run the Docker container:</p><pre> docker-compose up -d </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*sqszmnvt4WVhvj2p-fY8Wg.png" /></figure><p>The Docker container has started and is running now.</p><p>You can also verify if the container is running by running the below command:</p><pre>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cKEo6TBXY9OntO5aU0ufPw.png" /></figure><p>Now that the docker container with Postgres image is up and running, we are can use the psql CLI to enter the Postgres DB and perform SQL queries.</p><p>This is the psql command to enter the DB in Postgres:</p><pre>docker exec -it postgres-jwt-auth psql -U postgres -d postgres-jwt</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XIja0atZ_Mudd7S0KIOJ-w.png" /></figure><p>Now, we have successfully created a Postgres DB using Docker.</p><p>The scope of this article was just to demonstrate how to setup and run Postgres DB using docker on your computer.</p><p>Now, you can successfully connect to the Postgres DB and run your SQL queries according to your needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a66143db9d9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with environment variables(.env) in Golang]]></title>
            <link>https://medium.com/@roystatham3003/working-with-environment-variables-env-in-golang-69905edae6ea?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/69905edae6ea</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Mon, 13 May 2024 09:44:57 GMT</pubDate>
            <atom:updated>2024-05-13T09:44:57.235Z</atom:updated>
            <content:encoded><![CDATA[<p>We generally store DB credentials and other imporatnt project propeties in a separate config or properties file.</p><p>For example, in Spring Boot(Java) we use application.yml / application.properties to store this information and then we retrieve these details whenever required.</p><p>In Golang, the simplest way to achieve this is to use the .env file.</p><p><strong>How to do it</strong>?</p><p>Steps:</p><ol><li>Create a .env file in the project structure.</li><li>Then, declare your properties in the following format.</li></ol><p>YOUR_PROPERTY_NAME=PROPERTY_VALUE</p><p>3. These properties can be accessed in .go files using the “os” package.</p><p><em>See example below:</em></p><p>We stored the username and password required to connect to Rabbit Mq in the .env file and then accessed these properties in main.go file using the following two packages:</p><ol><li>“github.com/joho/godotenv”</li><li>“os”</li></ol><p>The godotenv package enables us to load the .env file and then we can use “os.Getenv(“Property Name”)” to access the specific property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhYBAA5nhlInjjSclR_FoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dy8Ja7AfMyigp0hVaiKCXw.png" /></figure><p>Read more about the godotenv package here: <a href="https://pkg.go.dev/github.com/joho/godotenv">https://pkg.go.dev/github.com/joho/godotenv</a></p><p>Read more about the os package here:</p><p><a href="https://pkg.go.dev/os">https://pkg.go.dev/os</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69905edae6ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Go Fiber: Create web applications with ease in Golang]]></title>
            <link>https://medium.com/@roystatham3003/go-fiber-create-web-applications-with-ease-in-golang-c1e98c6835b2?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1e98c6835b2</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Sun, 12 May 2024 18:54:39 GMT</pubDate>
            <atom:updated>2024-05-12T18:54:39.148Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Useful links:</strong></p><p><a href="https://github.com/rahulgubili3003/go-fiber-basic-app">GitHub - rahulgubili3003/go-fiber-basic-app</a></p><p>This is the GitHub link to my Go Fiber basic API code.</p><p><strong>What is Go Fiber?</strong></p><p><em>Go Fiber</em> is a web framework designed for Go, built on top of Fasthttp, known for its speed and efficiency. It aims to simplify web development in Go by focusing on minimalism and performance.</p><p>The code below is the snippet from the main.go file which uses the Go Fiber framework to create a basic API that responds with a Json response on the path <em>“/ping”.</em></p><p>The server runs on port 3000.</p><pre>package main<br><br>import (<br> &quot;github.com/gofiber/fiber/v2&quot;<br> &quot;log&quot;<br>)<br><br>func main() {<br> // Initialize<br> app := fiber.New()<br><br> // Accepts the request on this path and return the Json value as mentioned<br> app.Get(&quot;/ping&quot;, func(c *fiber.Ctx) error {<br>  return c.JSON(fiber.Map{<br>   &quot;message&quot;: &quot;Hello, we are using Go Fiber!!&quot;,<br>  })<br> })<br><br> // Listen on Port 3000<br> err := app.Listen(&quot;:3000&quot;)<br> if err != nil {<br>  log.Fatal(err)<br> }<br>}</pre><p><em>Testing the API on Postman:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GoZpPWFp5ZwyzuGlDpkVow.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1e98c6835b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting to a Database: Golang + Docker]]></title>
            <link>https://medium.com/@roystatham3003/database-connection-golang-docker-dfff9e958e47?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/dfff9e958e47</guid>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Sun, 12 May 2024 02:40:28 GMT</pubDate>
            <atom:updated>2024-05-14T09:54:28.488Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Connecting to a Database: Golang + Docker</strong></p><p>In this article, I shall explain how to connect to PostgreSQL Database from a Go program using the standard database/sql package.</p><p><strong><em>Prerequisites:</em></strong></p><ol><li>Docker</li><li>GO</li></ol><p><em>Steps:</em></p><ol><li>Pull the docker image for PostgreSQL from DockerHub using the below command.</li></ol><pre>docker pull postgres</pre><p>You will see this message after the docker image download is complete.</p><p><em>Status: Downloaded newer image for postgres:latest</em></p><p>2. After the docker image is pulled, then, instantiate a Docker container.</p><pre>docker run --name go-postgres-demo -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres</pre><p>This command creates a Docker container with name “go-postgres-demo” and runs the postgres docker image on the port 5432:5432.</p><p>3. Run “docker ps” command to verify if the docker container is up and running.</p><p>You will see something like this:</p><pre> docker ps                                                                                 <br>CONTAINER ID   IMAGE      COMMAND                  CREATED                  STATUS         PORTS                                       NAMES<br>24702b257d23   postgres   &quot;docker-entrypoint.s…&quot;   Less than a second ago   Up 3 seconds   0.0.0.0:5432-&gt;5432/tcp, :::5432-&gt;5432/tcp   go-postgres-demo</pre><p>4. Now, run a command to create a DB in Postgres.</p><pre>docker exec -ti go-postgres-demo createdb -U postgres postgres-demo</pre><p>This will create a DB called “postgres-demo”.</p><p>5. You can actually verify the connection to the newly created DB using the psql command.</p><pre>docker exec -ti go-postgres-demo psql -U postgres</pre><p>6. Execute the following commands to successfully verify the connection to the DB.</p><pre>psql (16.3 (Debian 16.3-1.pgdg120+1))<br>Type &quot;help&quot; for help.<br><br>postgres=# \c postgres-demo<br>You are now connected to database &quot;postgres-demo&quot; as user &quot;postgres&quot;.<br>postgres-demo=# \q</pre><p>7. Now, the DB has been successfully created and we are able to verify the connection to that DB is happening successfully.</p><p>8. Now, we write a Go program to connect to the DB that we just created. See below for the Go program:</p><pre>package main<br><br>import (<br> &quot;database/sql&quot;<br> &quot;fmt&quot;<br> _ &quot;github.com/lib/pq&quot;<br> &quot;log&quot;<br>)<br><br>func main() {<br> fmt.Println(&quot;Starting connection with Postgres Db&quot;)<br> connStr := &quot;postgres://postgres:password@localhost:5432/postgres-demo?sslmode=disable&quot;<br> db, err := sql.Open(&quot;postgres&quot;, connStr)<br> defer db.Close()<br> if err != nil {<br>  log.Fatal(err)<br> }<br> if err = db.Ping(); err != nil {<br>  log.Println(&quot;DB Ping Failed&quot;)<br>  log.Fatal(err)<br> }<br> log.Println(&quot;DB Connection started successfully&quot;)<br>}</pre><p>This is a basic program in Go to connect to the Postgres DB.</p><p><em>Go output after successful DB connection:</em></p><pre>Starting connection with Postgres Db<br>2024/05/12 11:49:23 DB Connection started successfully</pre><p>Github: <a href="https://github.com/rahulgubili3003/postgres-with-go">https://github.com/rahulgubili3003/postgres-with-go</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfff9e958e47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grpc Basics: Creating a protobuf file (.proto)]]></title>
            <link>https://medium.com/@roystatham3003/grpc-basics-creating-a-protobuf-file-proto-a80f02e0143b?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/a80f02e0143b</guid>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Sat, 11 May 2024 12:22:16 GMT</pubDate>
            <atom:updated>2024-05-11T12:22:40.966Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>What is gRpc?</em></strong></p><p>gRPC is <strong>a modern open source high performance Remote Procedure Call (RPC) framework</strong> developed by Google that can run in any environment.</p><p>It allows communication between clients and severs written in completely different languages. This is possible because gRpc uses Protocol Buffer (protobuf) files.</p><p>Protocol Buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.</p><p>It’s like JSON, except it’s smaller and faster.</p><p>The format and structure of the .proto files (extension for the protocol buffer definition files) are same regardless of what language you are using the gRpc framework in.</p><p>That’s why Protocol Buffers are language and platform agnostic.</p><p>Now, how do these .proto files look? And, what is their structure and how are they defined?</p><p><strong><em>Example of protobuf file (grpc-service.proto)</em></strong></p><pre>syntax = &quot;proto3&quot;;<br><br>option go_package = &quot;./proto&quot;;<br>package proto;<br><br>message Request {<br>  int64 id = 1;<br>  string firstname = 2;<br>  string lastname = 3;<br>}<br><br>message Response {<br>  string message = 1;<br>}<br><br>service RegisterService {<br>  rpc RegisterUser(Request) returns (Response) {}<br>}<br><br></pre><p><em>Syntax breakdown:</em></p><p>The first line of the protobuf file consists of ‘syntax = “proto3”’.</p><p>Then, we define the structure of the data that is expected to be received and sent over the gRpc.</p><p>We define this request and response structure using the keyword ‘message’.</p><p>The ‘message’ block defines the structure of the data. Within it, we define certain fields depending on our requirement. In this example, ‘Request’ has 3 fields id, firstname and lastname. And, the data type is also defined along with declaration.</p><p>Similarly, we define for Response as well.</p><p>Then, we define the ‘Service’.</p><p>Our application will have a service called RegisterService which has a function called RegisterUser which accepts the Request and Response as defined.</p><p>The package defined at the top of the file denotes the package in which this grpc-service.proto file is present.</p><p>After finishing the definition of our .proto file, we need to compile this using the protoc compiler which then generates 2 golang files (pb.go)</p><p>Command:</p><pre>protoc --go_out=. --go-grpc_out=. proto/grpc-service.proto</pre><p>Then, run go mod tidy so that if there are any missing dependencies, they will be automatically added.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a80f02e0143b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a basic web server in Go using net/http package]]></title>
            <link>https://medium.com/@roystatham3003/create-a-basic-web-server-in-go-da1f37f7e724?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/da1f37f7e724</guid>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Sat, 11 May 2024 04:26:05 GMT</pubDate>
            <atom:updated>2024-05-12T19:07:35.870Z</atom:updated>
            <content:encoded><![CDATA[<p><em>What is a Web Server?</em></p><p>Simple explanation:</p><p>A web server accepts client requests and sends responses accordingly. A client could be anything from web browsers to API clients like Postman etc.. These requests are served over the Web using protocols like HTTP/HTTPS.</p><p>So, now we are going to create a basic web server using Golang. This webserver accepts requests from the client over the web and generates some pre-defined responses.</p><p><strong>Prerequisites:</strong></p><ol><li>Install Golang on your computer(Latest Version)</li></ol><p>Check if Golang is installed on your computer by using this command:</p><p><em>go version</em></p><p>If it is already installed, then you will get the following response on your terminal showing the installed Golang version.</p><p><strong><em>go version go1.22.1 darwin/amd64</em></strong></p><p>Let’s start coding for the web server.</p><p>Note: In this example, we are going to create a Http server which accepts the request from the web client and then just prints a pre-defined (hardcoded) output.</p><p><strong>Steps:</strong></p><ol><li>Create an empty directory.</li><li>Then initiate the go.mod file with the module name of your choice. (go mod init &lt;module-name&gt;)</li><li>Then under the /main sub-directory create the main.go file. (The main.go file is the main entry point of the application from where the program execution starts)</li><li>We need to import two modules (“fmt” and “net/http”) -&gt; The net/http module in Go is a package that provides functionalities for creating HTTP clients and servers.</li><li>Then, we need to create a Handler function that prints the output based on a specific route.</li><li>After writing the entire code. Run the main function. The Web server gets initiated and you can basically test from the browser or Postman.</li></ol><p><em>See detailed code below:</em></p><p><strong><em>main.go</em></strong></p><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;net/http&quot;<br>)<br><br>func main() {<br> http.HandleFunc(&quot;/basic&quot;, handler)<br> // Listen on port 8080<br> fmt.Println(&quot;Server is listening on port 8085...&quot;)<br> if err := http.ListenAndServe(&quot;:8085&quot;, nil); err != nil {<br>  fmt.Printf(&quot;Error starting server: %v\n&quot;, err)<br> }<br>}<br><br>func handler(w http.ResponseWriter, r *http.Request) {<br> _, err := fmt.Fprintf(w, &quot;Welcome to the basic Http server&quot;)<br> if err != nil {<br>  return<br> }<br>}</pre><p><strong><em>go.mod file</em></strong></p><pre>module github.com/rahulgubili3003/basic-web-server-go</pre><p><strong><em>Project structure:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rs9oOynS2_Dg6n9-OdSsLQ.png" /></figure><p><strong><em>Test the web server:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1_Fi0jKhO8ZGnzB_F_2hA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da1f37f7e724" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tips for writing better Utility classes in Java]]></title>
            <link>https://medium.com/@roystatham3003/java-hacks-101-series-12182ba33c43?source=rss-0b5a88ca9382------2</link>
            <guid isPermaLink="false">https://medium.com/p/12182ba33c43</guid>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Rahul Gubiligari]]></dc:creator>
            <pubDate>Fri, 12 Apr 2024 12:01:38 GMT</pubDate>
            <atom:updated>2024-05-11T06:29:44.891Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>How to cleanly write Utility classes in Java?</em></strong></p><blockquote>Definition:</blockquote><p>What are Utility classes?</p><p>In our application, when we encounter a situation where we have to perform a certain function/operation multiple times, then instead of writing that piece of repetitive logic in all instances, we can simply delegate that logic to an external class.</p><p>Note: Here, <em>external</em> does not mean external to the project, but, creating a separate utility class under a separate “util” directory.</p><p>So, we write this repetitive method/function/logic in the utility class.</p><blockquote>What is the structure of the utility class?</blockquote><p>It is an ordinary class like any other class in your application, but, while defining the utility methods in this class we need to keep a few things in mind.</p><p>The utility methods in this utility class should be static.</p><p>This is more of a code convention followed widely in the industry.</p><p><strong><em>Ex:</em></strong></p><p>In the below code snippet, you can see that a BuilderUtil class has been defined and it has 2 static methods to build a couple of Entity objects.</p><p>You can note that both methods are <em>static.</em></p><p>Utility methods are static for mainly the following reasons:</p><ol><li><strong>Statelessness</strong>: Utility classes are typically stateless, meaning they do not maintain any state information. This characteristic makes them ideal for static methods, which also do not operate on an instance of a class but rather on the class itself. Static methods can be called without creating an instance of the class, which aligns with the stateless nature of utility classes.</li><li><strong>Reuse Across Instances:</strong> Static methods allow for the reuse of standard behavior across instances of different classes. This is particularly useful for utility methods, which often provide common functionalities that are not tied to the state of a specific object. By being static, utility methods can be easily reused across different parts of an application without the need to instantiate the utility class. -&gt; <strong><em>(Which is one of the main reasons for the creating Utility classes)</em></strong></li></ol><p>So, to summarise, the utility methods are made static because static methods can be called using just the <em>class name </em>without having to create an instance of the utility class whenever we want to use the utility methods.</p><p>This way, the utility methods are not tied to instances, rather, they would be universally accessible. Utility classes and methods are designed to be simple and clear, focusing on providing specific functionalities without the complexity of object-oriented programming. Static methods contribute to this simplicity by being directly associated with the class rather than an instance of the class.</p><p>Note: As a good coding practice, always create a private no-args constructor for the utility class so that the Utility class cannot be instantiated.</p><p>This design pattern ensures that utility methods are not tied to any specific instance of the class, further emphasizing their utility nature.</p><pre>@NoArgsConstructor(access = AccessLevel.PRIVATE)<br>public class BuilderUtil {<br><br>    public static RoomEntity buildRoomEntity(@NotNull final RoomAddRequest roomAddRequest) {<br>        return RoomEntity.builder()<br>                .roomNumber(roomAddRequest.roomNo())<br>                .roomType(roomAddRequest.roomType().getRoomTypeId())<br>                .floor(roomAddRequest.floor())<br>                .build();<br>    }<br><br>    public static RoomAddResponse buildRoomAddResponse(@NotNull final RoomEntity roomAdded) {<br>        return RoomAddResponse.builder()<br>                .id(roomAdded.getId())<br>                .floor(roomAdded.getFloor())<br>                .roomNo(roomAdded.getRoomNumber())<br>                .roomType(RoomType.getByRoomTypeId(roomAdded.getRoomType()))<br>                .build();<br>    }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12182ba33c43" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>