Posts

golang oauth2 facebook example

Image
Todays most sites are integrates with social platforms like twitter, facebook, google plus for one or other purpose. I am writing this post to show how you can intgreate  facebook  with your golang app using facebook oauth2.

Just Some Word About OAuth2

OAuth 2 is an authorization framework that enables applications to obtain limited access to user accounts on an HTTP service, such as Facebook, GitHub, and DigitalOcean.
For More information read this articel ReadMore
Create App With FacebookTo intgreate facebook with your golang app first of all you have to need a facebook app_id and app_secret. Those are app idetifiers for facebook. 

To create an app in facebook you should have account on facebook ( and i think you might have already ). Using your facebook accout login on developer.facebook.com



 After login click on MyApps dropdown and click on Add a New App Button




Create New AppId by providing Display name and contact email address.
After creation of your new app you will see the dashboard o…

String trim in the golang

I found it somewhat confusing at first sight and done lots of buggy code due to misunderstanding of the trim functions.
TrimLeft
func TrimLeft(s string, cutset string) string as shown in the trimleft function it takes two arguments  Input stringcutset string Here cutset string is not the string it means the string made of the runes you want to trim from left side untill a rune found that is not defined in the cutset string
For example,

cutted_string := trimleft ( "hello manish","he")fmt.println(cutted_string )

It will give output string as  "llo manish"
Now lets edit the cutset string,
cutted_string := trimleft ( "hello manish","hel")

fmt.println(cutted_string )
If you are like me you might expecting this output "lo manish" But its exctual ouput is "o manish" The reason is trim left trims the runes ( charactres ) from left side utill a rune found that is not inside the cutset list.  If you want to trim the string/word "hello&q…

Parse Custom Delimeter Seperated File In Golang With encode/csv Package

Image
Package csv reads and writes comma-separated values (CSV) files. There are many kinds of CSV files; this package supports the format described in RFC 4180.
A csv file contains zero or more records of one or more fields per record. Each record is separated by the newline character. The final record may optionally be followed by a newline character. For More


CSV stands for the " comma seperated values ", But you can parse the file with any custom defined delimeter with the encode/csv package of golang. For example ,you can use pipe ( | ) symbol or underscoer (_) as delimiter insted of comma.


Writing A Pipe Seperated File With encode/csvHere is the example in which we are encoding the string of array to a csv
Here we are sending output to standard output. But you can also store it in file.
Output Is
First_name|last_name|username
Rob|Pike|rob
Ken|Thompson|ken
Robert|Griesemer|gri





You can also read a file with custom delimiter.The paramter that defines the delimiter is w.Comma. Here Comma f…

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…