Posts

Showing posts from April, 2018

Host Multiple Web Sites of Go Using Reverse Proxy Example

Image
Go supports built-in server. But there is a limitation that you can host only one site at once with one port.
Though you can host multiple sites with the domain name using gorilla mux then all site will come with one app that will be very hard to maintain and update. 
Another option is you can host your sitewith different ports and then use the reverse proxy to map to map the domain name to the port




ExplanationScenario I have two sites running on my vultr vps. All of them are website that means request will be come in with  domain name and going to be arrived on the port 80. If  I assing one program [ site ] to listen to the port 80 others will not be able to listen on port 80. 

Condition
Requirement is that requests should be listend on port 80 and handled by the app to which it relates.
After struggling for 3 days i got this 😂 silly solution.


Source Code ( solution I got ) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17func main() { // New functionality written in Go http.HandleFunc(&…

use elasticmail api with golang example

Image
I am not going describe anything about elasticmail itself. You can look at the elasticmails site for details about it.

I am writing this post to show you how to use it with your GoLang application.

First Create a template in the elastic mail panel. I Don't know why but when I tried to send an email as complete HTML string. It was returning the 404 error.

But when using small pieces of HTML tags like just passing

<h2> Hello </h2> it was working.

So instead of struggling with it, I found another way,
Create Custome template on the elasticmails site panelUse the template for mail with passing necessary details[fields] during the API call


Create A Template with placeholders

Highlighted elements from the left side
Templets menuTemplet Name / IdExample Placeholders
GoLang Code function to send the email through ElasticMail with the template shown in the image with the firstname and lastname


func ElasticMailSend(){ mailClient := http.Client{ Timeout: time.Minute * 1, } myurl := url…