Posts

Showing posts from November, 2017

Getting Started With Google Api client - Golang

Image
Almost every google api i have integreated with my golang projects have same step.
1. Authroize the user
2. Get the token for user
3. Get the cilent using the token
4. Make furter requset for google api using the client


Google api client for golang can be get here

here is the example code

end of example code


Now lets inspect the code what it does.


Start from main function where the program starts the exection
[line 94] Main function starts[line 96] We are reading the client_id.json file downloaded from the google cloud. It will have information like client_id , project_id, token_id, etc. If you don't have client_id.json create a new one.[line 103] We are reading the json file and adding the permission we want for app on using the ConfigFromJson fucntion. [line 107] We are getting the http client for the further google api requests using the getClient function.Here This function calls subfunctions[line 24] tokenCacheFile function trys to load the cache the file already stored in local syst…

How To Configure Sendy on Ubuntu 16.04 with nginx

Image
How To Configure Sendy on Ubuntu 16.04 with nginx


Introduction
Sendy is a self hosted email newsletter application that lets you send trackable emails via Amazon Simple Email Service (SES). You can host it on your vps. We are going to see how to host the Sendy on Ubuntu server having installed php , mysql and nginx

Prerequisites
Before you begin this guide you'll need the following: VPS with ubuntu 16.04PHPMySQLnginx
Step 1 — Get the licenced copy of sendySendy is a commercial product. You have to purchase it before using it. You can purchase it fromhttp://sendy.co After purchasing they will send you a copy of the sendy to your email id. Now transition to the next step by telling the reader what's next.


Step 2 — Configer SendyExtract the zip of sendy you get in the email Update the config.php file You will be able to find config.php file inside the include folder.Update the varialbes inside config.php
Set the App_PATH & Set the mysql credentials /* Set the URL to your Sendy installati…

Export enviroment variable in linux

Image
For User & ApplicationThere are actully three files from the linux reads the enviroment variable

/etc/enviromet ~/.profile :~/.bashrc 
If your app depened on the enviroment variable then you have to store that variable inside this files otherwise those variable lost as soon as the terminal exits.

To export enviroment variable permanatly in linux follow this commands :

$ echo export variablename='path/value' >> ~/.profile
This will store the variable in the ~./profile


$ echo export variablename='path/value' >> ~/.bashrc
This will store the variable in the ~./bashrc

Now to make this change working you have to run this commands

$ source ~/.profile 
This will evaluate ~/.profile file

$ source ~/.bashrc
This will evaluate ~/.bashrc file


You can locate this files in you users Home folder


If you want to go GUI way you can find this files in your /home/[user] folder



For CronJob
This will not work if you have to use the enviroment variable in the cron job

If you want to set the…

golang intellij community setup

Image
I have used the phpstorm for 2 years. So intellj platform is now first need for development. There are many options available as golang development ide.
like Sublime and Atom etc.

If you are reading this means i don't have to give reasons why to use intellj for development. ( But if you are not familier with intellj platform you can check it out here. )


Intellj Community Version as Golang IDEI am assuming that you now how to setup the golang on your own spacific platform.
After you setup the golang
you need to download install intellj community version.
( Note that Community version is open source and free while other versions are commercial. Here is the comparision of Intellj Community version with commercial versions )

Here is the spacific link for the intellj communiy verions.
I would sugget to use the link provided here because i have felt early that golang plugin (which is essential to use golang inside the community version) is not compatible with the latest version.
https://www.jetb…

Easy way deploy and manage mysql database to linux server

Let assume that you have setup the linux server with mysql. Now you want to deploy the database to the server you have created on your developement enviroment. 

You development enviroment may be windows or mac or linux with the gui but server are run only cli.

So it is necessary to know the easy way to deploy database to the server with just cli


Importing the mysql database to mysql using the cli
1) Export the sql file of the database from your development enviroment.

2) Copy the sql file to the serve using the sftp.

3) Now import the sql file to you mysql using this comman snippet

    $ mysql -u [username] -p < [path/to/your/sql/file] 
    $ password : [your password ] [will be invisible on screen]
    $ 

After sucessfull import of sql file your database will ready to be used.

Note that if there is any error during the import than it will print the error on the screen but in case of successful import it will not generate any response.


Now to access the database deployed on the server you may…

golang secure api with jwt

Image
For jwt authnetication i am using the dgrijalva/jwt-go package with my golang project. 

First of all fetch packge from repository
go get github.com/dgrijalva/jwt-go

Now you are ready to use the jwt

I am sharing here  my basic code to create secure routes using jwt

Here you can see that we have used jwtcheck function as middleware. It processes the request before passing it forward. If request has a valid jwt token than that request get forwarded to the intended function otherwise that request does not forwarded.
Hope you find it usefull. If you have any question just ask in comments.