<?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 Parvin Eyvazov on Medium]]></title>
        <description><![CDATA[Stories by Parvin Eyvazov on Medium]]></description>
        <link>https://medium.com/@ParvinEyvazov?source=rss-3d5f91fc6957------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*btqX1iRCzoqjoBM13B4EDw.png</url>
            <title>Stories by Parvin Eyvazov on Medium</title>
            <link>https://medium.com/@ParvinEyvazov?source=rss-3d5f91fc6957------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 10:55:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ParvinEyvazov/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[Golang & WebAssembly — build a Web app with them]]></title>
            <link>https://medium.com/@ParvinEyvazov/golang-webassembly-build-a-web-app-with-them-28679ebcb2a1?source=rss-3d5f91fc6957------2</link>
            <guid isPermaLink="false">https://medium.com/p/28679ebcb2a1</guid>
            <dc:creator><![CDATA[Parvin Eyvazov]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 16:19:17 GMT</pubDate>
            <atom:updated>2022-08-14T16:21:17.574Z</atom:updated>
            <content:encoded><![CDATA[<h3>Golang &amp; WebAssembly — build a Web app with them</h3><p>Technology is getting more enjoyable and interesting way day by day. Options are getting more with the day for solving problems. This can be understood in both bad and good. Most of the time there is always a better way of solving a problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*h7SNtwJ8Dnq-TlKKajv_5A.png" /></figure><p>less talk more action!</p><p>This post will try to give brief information about how to develop a simple Web app using Golang &amp; WebAssembly. We will develop an app that will encrypt the URL that we gave and create a new encrypted URL for redirection. For encryption &amp; decryption, we will use the Blowfish Encryption Algorithm (Don’t need to know about the details of this algorithm).</p><p>Project: <a href="https://ghost-url.netlify.app/">ghost-url.netlify.app</a></p><p>Source code: <a href="https://github.com/ParvinEyvazov/ghost-url">github.com/ParvinEyvazov/ghost-url</a> (don’t forget to leave a star⭐)</p><p>The project mainly consists of 3 parts.</p><ul><li>Logic (Go)</li><li>UI (HTML/CSS and a bit js)</li><li>WebServer (Go)</li></ul><h3>1. Project/Folder Setup</h3><pre>├ cmd<br>│   |-- wasm<br>│   |   |-- main.go<br>│   |-- webserver<br>│   |   |-- main.go<br>├ core<br>│   |-- core.go<br>│   |-- decrypt.go<br>│   |-- encrypt.go<br>├ static<br>│   |-- index.html<br>│   |-- loadwasm.js<br>│   |-- main.wasm<br>│   |-- styles.css<br>│   |-- wasm_exec.js<br>├ url<br>|   |-- url.go<br>go.mod<br>go.sum</pre><h3>2. How does it work overall?</h3><p>We are developing the logic code using Go and compile to the .wasm (WebAssembly) file. Inside our js scripts, we load this .wasm file and run the functions that we wrote. And let’s get into the codes.</p><h3>3.1. Logic (Go)</h3><p>Our logic codes are in cmd/wasm/main.go file. Here are the codes:</p><p>cmd/wasm/main.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f5cca5f8a2399eaf218054d0e61d379/href">https://medium.com/media/2f5cca5f8a2399eaf218054d0e61d379/href</a></iframe><p>Basically, we are creating 2 functions to use in our js.</p><ul><li>ghostUrl</li><li>recoverUrl</li></ul><p>ghostUrl is encrypting the URL provided by the user and returns the encrypted one. When a user comes with the encrypted URL to the app, recoverUrl is decrypting the URL and returning to js and inside js, the page redirects the user to this URL. This is kind of working like URL shorteners, but not saving them to the Database.</p><pre>js.Global().Set(&quot;ghostUrl&quot;, js.FuncOf(ghostUrl))<br>js.Global().Set(&quot;recoverUrl&quot;, js.FuncOf(recoverUrl))</pre><p>These codes are working kind of bridge functionality from Go (compiled .wasm) to the Js file.</p><p>These are the Blowfish encryption and decryption codes:</p><p>core/core.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/09b7c49cea9b7e4875d659e0d4c5a564/href">https://medium.com/media/09b7c49cea9b7e4875d659e0d4c5a564/href</a></iframe><p>For Decryption (from string to string)</p><p>core/decrypt.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8c099b10d6ff5f54946020607f5512d/href">https://medium.com/media/f8c099b10d6ff5f54946020607f5512d/href</a></iframe><p>For Encryption (from string to string)</p><p>core/encrypt.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f38c752b215c82221177d5d17a86844e/href">https://medium.com/media/f38c752b215c82221177d5d17a86844e/href</a></iframe><p>For the URL operations</p><p>url/url.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc42de17d288553281a61be4aa3a2deb/href">https://medium.com/media/cc42de17d288553281a61be4aa3a2deb/href</a></iframe><h3>3.2. UI (HTML/CSS and a bit js)</h3><p>For UI we will surely use the building blocks of Web application which is HTML and CSS. For communicating between WebAssembly and UI we will use a bit of JavaScript. Let’s start with the HTML file. static/index.html is the file starting point.</p><p>static/index.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b1b261ef6d021ac5c0926ca8e04eb85/href">https://medium.com/media/1b1b261ef6d021ac5c0926ca8e04eb85/href</a></iframe><p>Loading .wasm file for using:</p><p>static/loadwasm.js</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79b4abc4e4ed47a4931a769e73ada490/href">https://medium.com/media/79b4abc4e4ed47a4931a769e73ada490/href</a></iframe><p>Style:</p><p>static/style.css</p><p>Would be better if you copy it from here (because of the number of lines): <a href="https://github.com/ParvinEyvazov/ghost-url/blob/master/static/styles.css">static/style.css</a></p><p>And a JavaScript file provided by Go to load your .wasm file into a Web page. It is a dynamic file, and because of that would be awesome if you always install the latest version of it from Go itself. You can also copy it from the URL provided below.</p><p>static/wasm_exec.js</p><p>There are 2 ways.</p><ul><li>Copy from Go source (run this in project folder terminal):</li></ul><pre>cp &quot;$(go env GOROOT)/misc/wasm/wasm_exec.js&quot; ./static/</pre><p>OR</p><ul><li>Create a static/wasm_exec.js file and copy from <a href="https://github.com/ParvinEyvazov/ghost-url/blob/master/static/wasm_exec.js">here</a></li></ul><h3>3.3. WebServer (Go)</h3><p>It will be a basic HTTP file server written in Go. Here, we will basically serve our ./static folder. Here is the code:</p><p>cmd/webserver/main.go</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9846c0961e50a5cd145b15897cb9de8/href">https://medium.com/media/f9846c0961e50a5cd145b15897cb9de8/href</a></iframe><h3>4. Run the project</h3><p>We finally completed the code part and let’s run our project:</p><ul><li>Create .mod file</li></ul><pre>go mod init &lt;project name&gt;<br>go mod tidy</pre><p>Don’t forget to update names of the packages in the imports sections of cmd\wasm\main.go and cmd\webserver\main.go.</p><p>For my scenario</p><pre>go mod init github.com/ParvinEyvazov/ghost-url<br>go mod tidy</pre><ul><li>Build the .wasm file (will compile it into ./static file)</li></ul><pre>GOOS=js GOARCH=wasm go build -o static/main.wasm cmd/wasm/main.go</pre><ul><li>Run the project</li></ul><pre>go run ./cmd/webserver/main.go</pre><ul><li>Open in browser</li></ul><p><a href="http://localhost:3000/">http://localhost:3000</a></p><p>If any error occurs on running or building steps, please take a look at the source code here: <a href="https://github.com/ParvinEyvazov/ghost-url">github.com/ParvinEyvazov/ghost-url</a></p><p>My local Golang version is 1.18.1</p><p>That is all you need to run Go on Web UI using WebAssembly.</p><p>I hope this blog will be helpful to you. <strong>Thanks for reading and have a wonderful day :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28679ebcb2a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>