<h1>Go Gin vs HttpRouter(Update)</h1>

Suprised!

I made an update on my tools.zh-code.com and observed something fun and interesting.

HttpRouter:

Gin:

I guess I need to test to figure it out…

I was thinking this would be something may be a problem. However, I am really satisfied with my result and I do think this is a really fun experience.

BTW, you can bind custom HTMLRenderer to gin, since gin by default only renders one template. So I binded html/template as the HTMLRenderer and it’s working just fine.

<h1>Gonic Gin vs HttpRouter</h1>

TL:DR: I prefer HttpRouter.

Story begins:

Okay… It’s been not a really long story at this point. Recently, I am working on a website for apps that I wrote and will use frequently and personally… If you are interested, please take a look at https://tools.zh-code.com

I was using HttpRouter with html/template to render pages and taking api requests.

Yesterday, I was wondering about swagger UI for the APIs and make the apps I wrote open by API requests as well. To start, I asked Dr.Google to see if there are any open source golang libraries can generate Swagger documentation on the fly based on comments. Swaggo seems to be a really interesting idea, and then another post catches my eyes Gin-Swaggo.

Gin was something I really wanted to try and it looks much more powerful then HttpRouter. However, there is a catch, performance. I know, the 20% difference will never be the bottleneck, especially for routers. Most of the cases, the bottleneck will be database. However, 20% of performance trade for a better features, I would need to think about it. As part of now, there are basically no traffic to my site except me, so I should have no problem even using .Net(I am working as a fullstack .Net developer so I can just joke myself).

This morning, I gave Gin a shot. Since the FunApps website is still new, so I was thinking why don’t I convert it to Gin. Let’s start.

1. Converting the main function to use gin.Default() instead of httprouter.New()

Okay. Not a big deal, few lines of code change, just rename it. And see what happens next…

2. Change all functions to use (c *gin.Context)

Okay. Not too bad, not too bad. Still can do it with bulk replacing. After doing bulk replace, 200+ errors thrown. Okay, okay. I am expecting that.

3. Change previously handler functions to gin’s middleware

There are some digging into the syntax of how to use Context. I have to say, it’s super convenient. I wouldn’t expect something like this would amazed me so much. I love it! Okay, gin is the way to go now! (Too soon…)

4. Let’s load all the html templates to use gin’s router

Done.

5. Moment of truth.

Nested templates are not rendered correctly…. I have headers and footer in separate templates and container as the content template. Previously, I just need to execute content template. But now, it only renders the content page itself, which result to plain txt as html…

I went to search for what I did wrong about that one, however, nothing really explaining the reason to me clearly, and it’s close to the time to start doing my job remotely… Let’s hold on it for now. I am really want to give it another try next few days, but the question will be, why? After digging into gin, I had an idea what are the good things about gin. The context, and powerful middle wares. Why can I make it using httprouter? Also, I can only implement things I need from scratch and the performance will be just fine.

Yep. I still prefer more of httprouter to implement features only what I need. Even this takes time.

Hope this will help you to save some of your time. TBH, try gin, it’s awesome. However, if you want me to use it all the time, I really want to. However, for now, I will give it a pass. Let me dig into it again in next few days.

<h1>Farewell .Net. I will miss you</h1>

I’ve been a .Net developer for like 5+ years since college and I use .Net in work environment as well. It’s been a looong time using C#. I think it’s a good time to keep rolling my curiosity when I adapted my first programming language(Python) like almost 8 years ago.

A question I’ve keep asking myself, why? Is .Net not good anymore? No, it’s not. It’s still good, but also it’s not ideal for what I am going to do. .Net Core is fast, but it took too much memory in server. I have multiple services hosted in docker in my server, and all services are written in .Net Core. Each instance of service occupied 20 MB to 40 MB of ram just by idling. That’s a little bit to much for me. But that’s not the main reason. The main reason is to kick myself out of my comfort zone and going after something new and robust. Why? I’m a developer.

Go? Rust? C++?

These are languages I am interested in learning but I need to choose one to play with at this moment. C++ might not be a good choice since it’s been there for a while and might be replaced in the future. Nah. Is Rust good for this case? Might be. But it’s a bit too young. Go then. Probably. Let’s go for it for now. We will see if I like it after a month of rewriting my old Rest APIs.

Farewell .Net. I will miss you

<h1>Low cost SMS API</h1>

As you guys know, I do programming for fun and I do provide API services for public use. Most of the APIs are used by my other projects.

Recently, I created a new SMS API to send verification code and messages over text messages to US and Canada numbers. If you are interested, please take a look at https://rapidapi.com/zhcode/api/quicksms1. Compare to other text messaging service providers, mine will be extreme low cost. If you need one for your own, please let me know and I will have your personal ones setup.

If you have any other API ideas, please let me know and if I am interested, I will start working on it.

<h1>8.11.2019 – New Audi</h1>

Yeeeee. Just traded in my old Altima into a Audi Q8!!! It feels so good, but I still love you my Altima 😉

There are 3 cars I was looking into and wasn’t sure which one I really want until I took a test drive for Q8. The cars I was looking are GLC 63s Coupe, Audi Q8, and Porsche Macan. Why not electric like Tesla? Yeah, I get it… I am not a guy like that. Electric cars are the future, I agree with you, but I cant wait for 1 hour in a charging station(maybe more if I need to wait in a line). So I had an appointment with Mercedes yesterday and I took a test drive once I arrive. They didn’t have the coupe version at that point, since they understood me wrong in the email. They had a 43 SUV pulled out and I said it’s fine. The interior is basically the same and the HP is fine to see how it perform.

The acceleration it’s amaaazing. But. the interior is not something I really like, especially the screen. The edge is huuuuge. I am not sure why make something has that big edge, which makes the screen looks small. And I couldn’t wireless connect to Android Auto to the car. I do expect spending that much of money can save me a cord. This is not the case. Pass.

Today, two appointment scheduled. Audi and Porsche. Audi is at 12 and Porsche at 1:30pm. The time I stepped in the Audi and saw the Q8, I wasn’t expecting it to be this big, and got attracted by the front looking. After sitting inside the car, it’s basically the next 2 levels of the GLC. Nice looking and touch screen. Yeah, this is the one. The acceleration is fine, since Q8 is more into luxury instead of performance. I am fine with that.

It’s time to say “maybe next time” to Macan.

It took me 5 hours to purchase the car due to various of reasons. Eventually, my wife and I were so starving and the first stop for the new Audi is a restaurant :).

I like it, it’s right on spot.

<h1>Add Linux Swap Partition</h1>

Steps to add Swap Partition in Linux

Pre-requirements

Please use fdisk -l to get the target drive you want to use as the Swap space. Note: format the disk will lose all your data, Please back up before proceeding.

1. Format Disk into Linux swap / Solaris

$ fdisk /dev/sdb

Command (m for help): n
Command action: p
Partition number: 1
First cylinder: 
Last cylinder:

Note: Empty means use default value

command (m for help): t
Hex code: 82

command (m for help): w

2. Enable swap

$ mkswap -L swap1 /dev/sdb1

Modify /etc/fstab to add the line below

/dev/sdb1  swap  swap  defaults  0  0

3. Check Swap Space

$ swapon -a
$ swapon -s

<h1>Create Linux Swapfile</h1>

Create additional space use like “RAM”

1. Add Swap File

$ sudo fallocate -l 1G /swapfile

Create a 1GB swap file on Linux system

2. Set Swap File Permission

$ sudo chmod 600 /swapfile

3. Setup Linux Swap Area

$ sudo mkswap /swapfile

4. Enable the Swap

$ sudo swapon /swapfile

Modify /etc/fstab to enable the entry. Append the following line in the file

/swapfile swap swap defaults 0 0

5. Verify the swap status

$ sudo swapon --show