<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: penthaapatel</title>
    <description>The latest articles on DEV Community by penthaapatel (@penthaapatel).</description>
    <link>https://dev.to/penthaapatel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F172034%2F824c884a-b63c-440f-bfa4-b2cb404e804d.jpg</url>
      <title>DEV Community: penthaapatel</title>
      <link>https://dev.to/penthaapatel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/penthaapatel"/>
    <language>en</language>
    <item>
      <title>How to implement a simple gRPC service using Golang</title>
      <dc:creator>penthaapatel</dc:creator>
      <pubDate>Thu, 25 Mar 2021 06:08:26 +0000</pubDate>
      <link>https://dev.to/penthaapatel/how-to-implement-a-simple-grpc-service-using-golang-2hfk</link>
      <guid>https://dev.to/penthaapatel/how-to-implement-a-simple-grpc-service-using-golang-2hfk</guid>
      <description>&lt;h1&gt;
  
  
  How to implement a simple RPC service using Golang
&lt;/h1&gt;

&lt;p&gt;If you want a general introduction to RPC you might want to check out my previous article in this series - &lt;a href="https://dev.to/penthaapatel/a-concise-guide-to-grpc-for-beginners-49bc"&gt;A concise guide to gRPC for beginners&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The implemented code can be found on my GitHub Repository :&lt;br&gt;
&lt;a href="https://github.com/penthaapatel/grpcblog" rel="noopener noreferrer"&gt;Link to GitHub repository&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Before you begin
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://golang.org/doc/install" rel="noopener noreferrer"&gt;Install Golang&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grpc.io/docs/protoc-installation/" rel="noopener noreferrer"&gt;Install proto compilers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Workflow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Define protocol - Write .proto file&lt;/li&gt;
&lt;li&gt;Compile it - generate necessary protobuf related files and client and server stubs&lt;/li&gt;
&lt;li&gt;Write Client code&lt;/li&gt;
&lt;li&gt;Write Server code&lt;/li&gt;
&lt;li&gt;Run the server and client code, check if it works&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  A simple RPC service that can create blog posts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Client sends a request to the server to create a blog post with a given title and contents.&lt;/li&gt;
&lt;li&gt;The server saves the newly created blog posts in an in-memory storage.&lt;/li&gt;
&lt;li&gt;Since this particular article focuses on implementing RPC services, we use an in-memory storage to save out blog posts. This in-memory storage can be replaced with any database at the backend later.&lt;/li&gt;
&lt;li&gt;The database can be integrated later by utilising the power of interfaces in Golang.
### Directory structure
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grpcblog
├── Makefile
├── blog
│   ├── blog.pb.go
│   ├── blog.proto
│   └── blog_grpc.pb.go
├── client
│   └── client.go
├── server
│   └── server.go
├── storage
    └── storage.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  .proto file
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;message Blog&lt;/strong&gt; defines the structure of the blog post and contains 2 fields - &lt;strong&gt;title&lt;/strong&gt; and &lt;strong&gt;body&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;Blog&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;message BlogRequest&lt;/strong&gt; defines the structure of the client request - has 1 field - &lt;strong&gt;Blog&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;BlogRequest&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;Blog&lt;/span&gt; &lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;message BlogResponse&lt;/strong&gt; defines the structure of the server response - contains 2 fields - 

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;id&lt;/strong&gt; : a universally unique identifier (&lt;strong&gt;UUID&lt;/strong&gt;) generated on successful creation of a new post.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;created&lt;/strong&gt; : a boolean value set to true if CreatePost is successful; false otherwise.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;BlogResponse&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;created&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;The proto file contains a simple RPC service &lt;strong&gt;CreatePost&lt;/strong&gt; - client sends a single request to the server and the server responds back with a single response. The RPC service &lt;strong&gt;CreatePost&lt;/strong&gt; sends a &lt;strong&gt;BlogRequest&lt;/strong&gt; from the client and the server responds with a &lt;strong&gt;BlogResponse&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;  &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="n"&gt;BlogService&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="n"&gt;rpc&lt;/span&gt; &lt;span class="n"&gt;CreatePost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BlogRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BlogResponse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Compiling the .proto files
&lt;/h3&gt;

&lt;p&gt;Use the following command to compile the .protofiles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;protoc &lt;span class="nt"&gt;--go_out&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--go_opt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;paths&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;source_relative &lt;span class="nt"&gt;--go-grpc_out&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--go-grpc_opt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;paths&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;source_relative blog/blog.proto
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate two files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;blog/blog_grpc.pb.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;blog_grpc.pb.go&lt;/em&gt;&lt;/strong&gt; contains server and client stubs. The interfaces &lt;strong&gt;BlogServiceClient&lt;/strong&gt; and &lt;strong&gt;BlogServiceServer&lt;/strong&gt; are not implemented. These interfaces will be later implemented in our server and client code. We will have to write own own implementation of server and client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;blog/blog.pb.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;blog.pb.go&lt;/em&gt;&lt;/strong&gt; contains protocol buffer code - responsible for binary serialization of data when it is transported between server and client.&lt;/p&gt;

&lt;h3&gt;
  
  
  Define in-memory storage
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;storage.go&lt;/strong&gt; contains custom functions to implement the temporary in-memory storage.&lt;/li&gt;
&lt;li&gt;Contains an interface &lt;strong&gt;BlogStorage interface&lt;/strong&gt; with a &lt;strong&gt;Save()&lt;/strong&gt; and a &lt;strong&gt;View()&lt;/strong&gt; function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;BlogStorage&lt;/span&gt; &lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;blog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Blog&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;error&lt;/span&gt;
    &lt;span class="n"&gt;View&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;InMemoryBlogStorage&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;mutex&lt;/span&gt; &lt;span class="n"&gt;sync&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RWMutex&lt;/span&gt;
    &lt;span class="n"&gt;blogs&lt;/span&gt; &lt;span class="k"&gt;map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;blog&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Blog&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Blogs are saved in a map where key is the UUID and the value associated with it is the blog post.&lt;/li&gt;
&lt;li&gt;To save the posts to a database, we can add another function like &lt;strong&gt;SaveToDB()&lt;/strong&gt; that implements the &lt;strong&gt;BlogStorage&lt;/strong&gt; interface.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Client code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reads in the blog title from the console.&lt;/li&gt;
&lt;li&gt;Reads in the blog contents from the console.&lt;/li&gt;
&lt;li&gt; Contains the implementation of the function &lt;strong&gt;CreatePost&lt;/strong&gt; that was unimplemented in &lt;strong&gt;BlogServiceClient&lt;/strong&gt; interface in &lt;strong&gt;blog/blog_grpc.pb.go&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Server code
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Creates and saves new blog posts to the in-memory storage by taking input data from the client.&lt;/li&gt;
&lt;li&gt;Contains the implementation of the function &lt;strong&gt;CreatePost&lt;/strong&gt; that was unimplemented in &lt;strong&gt;BlogServiceServer&lt;/strong&gt; interface in &lt;strong&gt;blog/blog_grpc.pb.go&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Generates a universally unique identifier (UUID) when a new post is created and saved to the in-memory storage&lt;/li&gt;
&lt;li&gt;Displays UUID of each new post upon successful creation of a new post&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Final result
&lt;/h3&gt;

&lt;p&gt;Run the server and client code in two separate terminals. &lt;br&gt;
Run server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run server/server.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0j06rcueqi7fbmmi91d7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0j06rcueqi7fbmmi91d7.png" alt="Server running on terminal 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run client - Enter title and contents for the new blog post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run client/client.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fco0k1wpfas83qevzoayd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fco0k1wpfas83qevzoayd.png" alt="Client running on terminal 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And hurray! We have successfully created a new post using gRPC service.&lt;/p&gt;

&lt;p&gt;Further reading - Some useful resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://grpc.io/docs/languages/go/quickstart/" rel="noopener noreferrer"&gt;gRPC Go Quick Start&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/protocol-buffers/docs/gotutorial" rel="noopener noreferrer"&gt;Protocol Buffer Basics: Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://grpc.io/docs/languages/go/basics/" rel="noopener noreferrer"&gt;Basic introduction to gRPC in Go&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/protocol-buffers/docs/proto3" rel="noopener noreferrer"&gt;proto3 language Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>grpc</category>
      <category>go</category>
    </item>
    <item>
      <title>A concise guide to gRPC for beginners</title>
      <dc:creator>penthaapatel</dc:creator>
      <pubDate>Thu, 25 Mar 2021 06:02:57 +0000</pubDate>
      <link>https://dev.to/penthaapatel/a-concise-guide-to-grpc-for-beginners-49bc</link>
      <guid>https://dev.to/penthaapatel/a-concise-guide-to-grpc-for-beginners-49bc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;A series of simple, beginner friendly tutorials that explain the what, why and how of gRPC.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Getting started - Understanding RPC
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is RPC?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;RPC aka Remote Procedure Calls - are just like functions. &lt;/li&gt;
&lt;li&gt;These functions are executed on some remote system and hence the name. &lt;/li&gt;
&lt;li&gt;It follows a request - response model. &lt;/li&gt;
&lt;li&gt;A request is initiated from the client - this request is a function call with certain parameters and then, the server returns a response. &lt;/li&gt;
&lt;li&gt;Real world application - to construct distributed, scalable, client - server based applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  gRPC
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;gRPC is a technology to implement RPC APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufny41nu6jwc2wce0vwb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fufny41nu6jwc2wce0vwb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Can write servers and clients using different programming languages - a client written using Python can interact with a server written in Golang. &lt;/li&gt;
&lt;li&gt;By default gRPC uses protocol buffers as the interface definition language (IDL) to define the RPC services and the structure of the payload messages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Understanding protocol buffers and .proto files
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is protobuf?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Protocol buffers are a way to serialize structured data in an efficient manner.&lt;/li&gt;
&lt;li&gt;It uses the method of binary serialization, which is faster than text based serialization methods like JSON.&lt;/li&gt;
&lt;li&gt;The protobuf specification can be implemented in various programming languages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is a .proto file
&lt;/h3&gt;

&lt;p&gt;A .proto file will contain the necessary definitions to see the protocol buffers in action.&lt;br&gt;
A file with .proto extension will contain the definitions of &lt;strong&gt;messages&lt;/strong&gt; and &lt;strong&gt;services&lt;/strong&gt;. The services are analogous to procedures/functions and the messages are analogous to the data types of the parameters that can be passed to these functions. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;

&lt;span class="n"&gt;syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"proto3"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;UrlRequest&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="n"&gt;UrlResponse&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="n"&gt;Url&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;rpc&lt;/span&gt; &lt;span class="n"&gt;CallUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UrlRequest&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;UrlResponse&lt;/span&gt;&lt;span class="p"&gt;){}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above example, the first line of the file specifies that you're using &lt;code&gt;proto3&lt;/code&gt; syntax, &lt;strong&gt;CallUrl&lt;/strong&gt; is a &lt;strong&gt;service&lt;/strong&gt;, &lt;strong&gt;UrlRequest&lt;/strong&gt; and &lt;strong&gt;UrlResponse&lt;/strong&gt; are the &lt;strong&gt;message&lt;/strong&gt; definitions. We can see that the CallUrl acts as a function with input parameter as HelloRequest and output as UrlResponse. The message definitions can have &lt;strong&gt;fields&lt;/strong&gt; within them. Each field has a name and a type. Here we have &lt;strong&gt;req&lt;/strong&gt; field which has the data type string in UrlRequest and &lt;strong&gt;res&lt;/strong&gt; is a field whose data type is int in UrlResponse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important step - Compiling a .proto file&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This generates helper code to implement the server and client code in the programming language of your choice.&lt;/li&gt;
&lt;li&gt;The generated code also handles the parsing of structured data as the data is serialised into a binary format which can be transferred more efficiently as compared to text based serialisation methods like JSON, XML.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Further Reading&lt;/em&gt;&lt;/strong&gt; - &lt;a href="https://developers.google.com/protocol-buffers/docs/proto3" rel="noopener noreferrer"&gt;Language Guide (proto3)&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Code
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Basic Workflow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Define the protocol - Write a .proto file

&lt;ul&gt;
&lt;li&gt;Define messages&lt;/li&gt;
&lt;li&gt;Define RPC service procedures with their respective parameters and return types. There can be 4 types of RPC procedures:

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;simple RPC&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;server-side streaming RPC&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;client-side streaming RPC&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;bidirectional streaming RPC&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Compile .proto file - generates protobuf related code for binary serialization of data; also generates client and server stubs&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;Write Server and Client code using language of your choice with the help of the generated stubs

&lt;ul&gt;
&lt;li&gt;gPRC currently supports the following languages -

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://grpc.io/docs/languages/csharp/" rel="noopener noreferrer"&gt;C#&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/cpp/" rel="noopener noreferrer"&gt;C++&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/dart/" rel="noopener noreferrer"&gt;Dart&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/go/" rel="noopener noreferrer"&gt;Go&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/java/" rel="noopener noreferrer"&gt;Java&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/kotlin/" rel="noopener noreferrer"&gt;Kotlin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/node/" rel="noopener noreferrer"&gt;Node&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/objective-c/" rel="noopener noreferrer"&gt;Objective-C&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/php/" rel="noopener noreferrer"&gt;PHP&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/python/" rel="noopener noreferrer"&gt;Python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://grpc.io/docs/languages/ruby/" rel="noopener noreferrer"&gt;Ruby&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;Compile and run the final application&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Further reading&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.grpc.io/docs/" rel="noopener noreferrer"&gt;gRPC Documentation&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.google.com/amp/s/cloudblog.withgoogle.com/products/api-management/understanding-grpc-openapi-and-rest-and-when-to-use-them/amp/" rel="noopener noreferrer"&gt;gRPC vs REST: Understanding gRPC, OpenAPI and REST and when to use them in API design&lt;/a&gt;&lt;/p&gt;

</description>
      <category>grpc</category>
      <category>protobufs</category>
    </item>
    <item>
      <title>Difference between functions and methods in Golang</title>
      <dc:creator>penthaapatel</dc:creator>
      <pubDate>Thu, 18 Mar 2021 03:43:28 +0000</pubDate>
      <link>https://dev.to/penthaapatel/difference-between-functions-and-methods-in-golang-5dgc</link>
      <guid>https://dev.to/penthaapatel/difference-between-functions-and-methods-in-golang-5dgc</guid>
      <description>&lt;h1&gt;
  
  
  Difference between functions and methods in Golang
&lt;/h1&gt;

&lt;p&gt;The words function and method are used almost interchangeably, but there are subtle differences in their implementation and usage when used in Golang. Let's see what the difference is and how its used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Function
&lt;/h3&gt;

&lt;p&gt;Functions accept a set of input &lt;strong&gt;parameters&lt;/strong&gt;, perform some operations on the input and produce an output with a specific &lt;strong&gt;return type.&lt;/strong&gt; Functions are independent that is they are &lt;strong&gt;not attached to any user defined type&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Syntax:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;FunctionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Parameters&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ReturnTypes&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There cannot exist two different functions with the same name in the same package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Rectangle&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
    &lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Circle&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Pi&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://play.golang.org/p/LQNBLtOfhFi"&gt;Run above code in The Go Playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above code throws an error :  &lt;code&gt;Area redeclared in this block&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Method
&lt;/h3&gt;

&lt;p&gt;A method is effectively a function attached to a user defined type like a &lt;strong&gt;struct&lt;/strong&gt;. This user defined type is called a &lt;strong&gt;receiver&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Syntax:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;ReceiverType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;FunctionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Parameters&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;ReturnTypes&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There can exist different methods with the same name with a different receiver.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Rectangle&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Width&lt;/span&gt;  &lt;span class="kt"&gt;float64&lt;/span&gt;
    &lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="n"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Circle&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Pi&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Triangle&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Base&lt;/span&gt;   &lt;span class="kt"&gt;float64&lt;/span&gt;
    &lt;span class="n"&gt;Height&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="n"&gt;Triangle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="kt"&gt;float64&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="m"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://play.golang.org/p/ASQP_J_RUSU"&gt;Run above code in The Go Playground&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
    </item>
    <item>
      <title>Using Multiple Linear regression to solve banknote authentication problem</title>
      <dc:creator>penthaapatel</dc:creator>
      <pubDate>Fri, 11 Oct 2019 02:11:40 +0000</pubDate>
      <link>https://dev.to/penthaapatel/using-multiple-linear-regression-to-solve-banknote-authentication-problem-18j5</link>
      <guid>https://dev.to/penthaapatel/using-multiple-linear-regression-to-solve-banknote-authentication-problem-18j5</guid>
      <description>&lt;p&gt;To predict whether a given banknote is authentic given a number of measures taken from a photograph.&lt;/p&gt;

&lt;p&gt;Dataset used - &lt;a href="http://archive.ics.uci.edu/ml/datasets/banknote+authentication"&gt;&lt;strong&gt;Banknote Authentication Data Set&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is binary classification problem. The dataset consists of 5 columns as follows: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attributes:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Variance of Wavelet Transformed image (continuous).&lt;/li&gt;
&lt;li&gt; Skewness of Wavelet Transformed image (continuous).&lt;/li&gt;
&lt;li&gt; Kurtosis of Wavelet Transformed image (continuous).&lt;/li&gt;
&lt;li&gt; Entropy of image (continuous).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Labels(Target)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Output (0 for authentic, 1 for inauthentic).&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Load the dataset
&lt;/h4&gt;

&lt;p&gt;Load dataset into a pandas dataframe from the csv file.&lt;/p&gt;

&lt;h4&gt;
  
  
  Analyse the data
&lt;/h4&gt;

&lt;p&gt;Using scatter matrix.&lt;/p&gt;

&lt;h4&gt;
  
  
  Prepare the data
&lt;/h4&gt;

&lt;p&gt;Break the data (labels and attributes) into two subsets: a test set and a training set.&lt;/p&gt;

&lt;h4&gt;
  
  
  Create the model
&lt;/h4&gt;

&lt;p&gt;Using Linear Regression.&lt;/p&gt;

&lt;h4&gt;
  
  
  Train the model
&lt;/h4&gt;

&lt;p&gt;Train the classifier using training set.&lt;/p&gt;

&lt;h4&gt;
  
  
  Evaluate the model
&lt;/h4&gt;

&lt;p&gt;Evaluate using test set.&lt;br&gt;
Generate confusion matrix for varying threshold values.&lt;br&gt;
Calculate misclassification rate.&lt;br&gt;
Calculate area under ROC.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dependence of Misclassification Error on Decision Threshold
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--luTx0IP8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lfmxthl5t0v6vttj4g6i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--luTx0IP8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/lfmxthl5t0v6vttj4g6i.png" alt="Error rate vs threshold" width="880" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  In-sample ROC for banknote classifier
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--L0aXmYga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cxlu9rsm9clg4k52ckdh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--L0aXmYga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/cxlu9rsm9clg4k52ckdh.png" alt="In-sample ROC" width="880" height="604"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Out-of-sample ROC for banknote classifier
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lc2-C-2C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wmk1src480ihpjai6u9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lc2-C-2C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1wmk1src480ihpjai6u9.png" alt="Out-of-sample ROC" width="880" height="619"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The entire code to this problem can be found on my github profile-&lt;br&gt;
&lt;a href="https://github.com/penthaapatel/BankNoteAuthentication"&gt;Code on GitHub - github.com/penthaapatel/BankNoteAuthentication&lt;/a&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>Contributing to Open Source Go projects on GitHub - A recipe to clone forked Go repos.</title>
      <dc:creator>penthaapatel</dc:creator>
      <pubDate>Sat, 08 Jun 2019 17:49:15 +0000</pubDate>
      <link>https://dev.to/penthaapatel/contributing-to-open-source-go-projects-on-github-a-recipe-to-clone-forked-go-repos-a87</link>
      <guid>https://dev.to/penthaapatel/contributing-to-open-source-go-projects-on-github-a-recipe-to-clone-forked-go-repos-a87</guid>
      <description>&lt;p&gt;Phew! It took me a while to figure out the entire process so I decided to write this post and I hope it'll further help everyone else get started. I managed to gather all the ingredients and curate the recipe to start working on an open source Golang project…so follow along.&lt;/p&gt;

&lt;p&gt;Say you want to experiment with &lt;strong&gt;org&lt;/strong&gt;'s new &lt;strong&gt;tool&lt;/strong&gt; which is written in Go. So, you &lt;strong&gt;go to get&lt;/strong&gt; (pun intended) the repo which you have &lt;strong&gt;forked&lt;/strong&gt; on your GitHub account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ocwkqed50iokvzwnryn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3ocwkqed50iokvzwnryn.png" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Question&lt;/em&gt; : Why your regular &lt;code&gt;go get&lt;/code&gt; on the forked repo won't work?&lt;br&gt;
&lt;em&gt;Simple Answer&lt;/em&gt; : All your imports will be messed up. You'll have to change all the import statements that say something like &lt;code&gt;github.com/org/tool&lt;/code&gt; to &lt;code&gt;github.com/yourGitHubID/tool&lt;/code&gt; to make things work and your code will run into conflicts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;go get&lt;/code&gt; the original &lt;strong&gt;org&lt;/strong&gt;'s repo. &lt;code&gt;go get&lt;/code&gt; clones the repo into your &lt;code&gt;GOPATH&lt;/code&gt; . &lt;code&gt;-u&lt;/code&gt; flag updates the named packages and their dependencies.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ go get -u github.com/org/tool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Go to the directory where you just cloned the &lt;strong&gt;org&lt;/strong&gt;'s &lt;strong&gt;tool&lt;/strong&gt; repo&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd $GOPATH/src/github.com/org/tool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's check what remote repos we have at this point. List out the remote repositories. &lt;code&gt;-v&lt;/code&gt; for a verbose output.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote -v
origin https://github.com/org/tool (fetch)
origin https://github.com/org/tool (push)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Add a add a new remote Git repository explicitly pointing at your fork. Here the shortname I used for the new remote is &lt;code&gt;fork&lt;/code&gt;, you can name it whatever you like.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote add fork https://github.com/yourGitHubID/tool.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;List out the remote repositories again to check and there you see it, a new remote has been added.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git remote -v
fork   https://github.com/yourGitHubID/tool.git (fetch)
fork   https://github.com/yourGitHubID/tool.git (push)
origin https://github.com/org/tool (fetch)
origin https://github.com/org/tool (push)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that you have a remote that points to the forked repo on your GitHub account, you can start working. To start working on a new branch:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git checkout -b experimentbranch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Make sure you have your branch updated with &lt;strong&gt;org&lt;/strong&gt;'s branch. Then you can start making changes to the files on the experimentbranch &lt;code&gt;git add&lt;/code&gt; your modified files and &lt;code&gt;git commit&lt;/code&gt; your work  after testing the new features you've added.&lt;/p&gt;

&lt;p&gt;Push changes to your fork.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push -u fork experimentbranch:experimentbranch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Then you can compare the changes you have made and submit a Pull Request to propose changes to be merged with the &lt;strong&gt;org&lt;/strong&gt;'s repository.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you notice any corrections that need to be made in the post feel free to comment below! :)&lt;/em&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>github</category>
      <category>opensource</category>
      <category>git</category>
    </item>
  </channel>
</rss>
