Firebase-integration-golang

Firebase integration for Golang

Since Golang is considering a lightweight programming language and Firebase is the next-generation Backend-as-a-Service, we think it could be a savvy combination to develop with ease both performant and secure microservices or stand-alone projects. Here are several advantages that could convince you to try this combo.

When it comes to Golang, it is as speedy as a compiled language, but it feels like an interpreted one. Moreover, as we mentioned in one of our previous articles, it has clean syntax with text-based workflow and clear language specification. Thus, you can write the code fast, and even faster compilation speeds are allowed for a rapid feedback style.

On the other hand, Firebase is an all-encompassing product that has everything you need to develop. From a real database to authentication modules. when you connect your app with Firebase, you’re not connecting through normal HTTP, but through a WebSocket which is much faster than HTTP and sends you new data as soon as it’s updated.

Firebase Storage provides a simple way to save binary files to Google Cloud Storage directly from the client thanks to its own system of security rules to protect your GCloud Socket from the masses while granting detailed write privileges to your authenticated clients.

Regarding Authentication, Firebase Auth has built in email/password authentication system. It also supports OAuth2 for Google, Facebook, Twitter and GitHub. Moreover, Firebase Auth integrates directly into Firebase Database so you can use it to control access to your data.

Last but not least, Firebase includes an easy-to-use hosting services for all your static files that serve them from a global CDN with HTTP/2 making your development particularly painless.

Firebase admin SDK for Golang

The Firebase Admin Go SDK enables access to Firebase services from privileged environments (such as servers or cloud) in Go. Currently, this SDK provides Firebase custom authentication support.

To install Firebase Admin Go SDK, simply execute the following command in a terminal from your $GOPATH:

go get firebase.google.com/go

Firebase Admin SDKs enable application developers to programmatically access Firebase services from trusted environments. They complement the Firebase client SDKs, which enable end users to access Firebase from their web browsers and mobile devices.

And that’s only the beginning. To explore further, here are 4 Go libraries and apps for Firebase that we think you will find useful:

Go-fcm - Firebase Cloud Messaging (FCM) Library using Golang (Go). This library uses HTTP/JSON Firebase Cloud Messaging connection server protocol. Its main features are: send messages to a topic, send messages to a device list, message can be a notification or data payload, supports condition attribute (fcm only), instance Id Features

Examples:

Send to A topic

package main

import (
	"fmt"
    "github.com/NaySoftware/go-fcm"
)

const (
	 serverKey = "YOUR-KEY"
     topic = "/topics/someTopic"
)

func main() {

	data := map[string]string{
		"msg": "Hello World1",
		"sum": "Happy Day",
	}

	c := fcm.NewFcmClient(serverKey)
	c.NewFcmMsgTo(topic, data)


	status, err := c.Send()


	if err == nil {
    status.PrintResults()
	} else {
		fmt.Println(err)
	}

}

Send to a list of Devices (tokens)

package main

import (
	"fmt"
    "github.com/NaySoftware/go-fcm"
)

const (
	 serverKey = "YOUR-KEY"
)

func main() {

	data := map[string]string{
		"msg": "Hello World1",
		"sum": "Happy Day",
	}

  ids := []string{
      "token1",
  }


  xds := []string{
      "token5",
      "token6",
      "token7",
  }

	c := fcm.NewFcmClient(serverKey)
    c.NewFcmRegIdsMsg(ids, data)
    c.AppendDevices(xds)

	status, err := c.Send()


	if err == nil {
    status.PrintResults()
	} else {
		fmt.Println(err)
	}

}

Firebase-server-sdk-go - This is the Server SDK written in Golang for the newly announced Firebase suite of services. This SDK, like its Java and Node counterparts, supports the following functions needed on the application server: Authentication, Real-time Database, Cloud Messaging (FCM)

Examples:

Create Custom Tokens

To create a custom token, pass the unique user ID used by your auth system to the CreateCustomToken() method:

auth, _ := firebase.GetAuth()
token, err := auth.CreateCustomToken(userId, nil)

You can also optionally specify additional claims to be included in the custom token. These claims will be available in the auth/request.auth objects in your Security Rules. For example:

auth, _ := firebase.GetAuth()
developerClaims = make(firebase.Claims)
developerClaims["premium_account"] = true
token, err := auth.CreateCustomToken(userId, &developerClaims)

Verify ID Tokens

To verify and decode an ID Token with the SDK, pass the ID Token to the VerifyIDToken method. If the ID Token is not expired and is properly signed, the method decodes the ID Token.

auth, _ := firebase.GetAuth()
decodedToken, err := auth.VerifyIDToken(idTokenString)
if err == nil {
	uid, found := decodedToken.Uid()
}

Fireauth - A Firebase token generator written in Go

cosn/firebase - This a library for invoking the Firebase REST API.

In conclusion, a combination of those two can lead you to solid and scalable application development. Golang might be the perfect solution to scale your idea, while Firebase has all that you could need to begin a worthwhile business solution or to launch your current configuration forward on the right track.


5 web development trends to look up in 2018

For succeeding in digital-based industries it's vital to accept tech changes and ride along with it. You can do this by exploring tomorrow's trends and seeking to integrate them into your business plan. And, when it comes to web development trends, sometimes they change faster than they can be implemented. That’s why it is important to be ahead of the game.

So, here are some in-demand web development trends that we believe you should look up this year:

1. Javascript

In our previous article, we underlined that Javascript continues to dominate on software development industry. Its position is strengthening even more in the last few years thanks to dozens of JS-related technologies existing and still in development. Now we are not just making small interactive elements in web pages anymore, we are building complex applications in JavaScript. And, it became more complicated to grasp the size and scope of the current JavaScript ecosystem.

One of the main items that benefit from the recent Javascript improvements, such as ES6 and ES7, is Functional Programming. Some useful improvements for functional programming are:

  • Arrow functions: Arrow functions reduce boilerplate when writing functions.
// functional ES6
const numbers = [1, 5, 8, 13];
const doubledNumbers = numbers.map((number) => number * 2);
  • Object/Array Spread: Object spread makes it really easy to avoid mutating objects because it is so much easier to create new objects that contain existing values.
// old school
var oldState = { email: 'foo@example.com', comment: 'i really like javascript' };
var newState = {};
Object.assign(newState, oldState, { ip: '192.168.5.87' });

// with spread
const oldState = { email: 'foo@example.com', comment: 'i really like javascript' };
const newState = { ...oldState, ip: '192.168.5.87' };
  • async/await: Their purpose is to simplify the behavior of using promises synchronously and to perform some behavior on a group of Promises.

ReactJS will also have an important role to play in 2018 thanks to its versatility. React keeps winning customer satisfaction surveys and according to indeed.com, React is the first library to pass jQuery in job popularity in a decade.

Moreover, the rise of Node.js has made JavaScript boundless. With the help of Node.js frameworks, JavaScript can be used in front-end, web server, desktop application, embedded system, databases and so on.  And, in 2018, there are some Node.js Frameworks that will stand out:

  • Express consists of features that assist in building a very powerful web and mobile apps as well as APIs. Extension package or plugins can be written in Express easily and be used quickly.
  • Sail.js (node.js mvc) is an ultimate solution as it comes with features that can build anything. It also makes database work easier irrelevant no matter what database is being used.
  • KOA handles flow control, error-handling and omits callback issues with the help of generators. It consists of modular approach and allows the user to write codes their own way to make it robust.
  • Meteor assists you build web and mobile apps through JavaScript. It has only one API which is utilized in both, client and server side. You can make a connection with anything with the database through its DDP protocol.
  • Derby.JS consists of Racer, a data synchronization engine, that assists in swift data sync amid database, sever as well as a browser.

2. Golang

Even though JS will still hold their superiority in 2018, Golang will strengthen its position - it is just the question of time.

Why is Golang became one of 2018 web development trends?

  • Development is fast, secure, and provides cross-platform support
  • The language is developed by Google and well-financed which guarantees its regular improvement.
  • Huge collection of open source packages and free official guides
  • It is the language of cloud infrastructure. Go is a part of Google Cloud, Microsoft Azure, AWS, Dropbox.

As we talked in one of our previous articles, Golang is a language of cloud industries and open source development. Both Cloud and OpenSource technologies are definitely going to grow in next 5 years - and Go programming is a perfect way of implementing these solutions.

Golang has 8 years on the market - so it’s relatively new. However, OverStack and GitHub statistics state that the number of Golang developers is already huge, and it is only going to grow.

3. Real-Time Apps

Real-time web apps, based on WebSockets, have been around for years, but they are getting more and more popular. The reason: users want fast interactions and real-time web apps are delivering on the need to share information instantly.

The main idea of real-time web apps is that a connection between client and server is left open, and the server pushes the new data once it’s there. Prior to real-time web apps, clients had to check back manually to find out if something new had happened.

While this has been very common in the world of Node.js, this trend is really spreading to other languages and frameworks as well. Even Ruby on Rails, a framework which has always relied heavily on server side rendering, and very long ignored the rise of Javascript single-page-applications, has seen the need for real-time (as you can see in Basecamp 3), and incorporated it under the name “ActionCable”.

4. Chatbots

As you probably noticed chatbots gained incredible popularity in 2017. And they will continue to evolve helping to increase communication online.

With chatbots, a company can provide a personalized experience that will enhance the quality of service through instant customer service 24 hours a day. In fact, many have predicted that 85% of all customer interactions will be done without human assistance by 2020.

It means that the customer service/care chatbots should turn into an essential aspect of every website this year. Nowadays consumers have become excessively demanding and want their issues to be resolved instantly, the customer service/care chatbots should top the priority lists of web development service providers.

5. Progressive Web Apps (PWA)

Not widely known, progressive web apps are similar to native mobile applications. Introduced in 2015, the concept of progressive web apps are anticipated to compete for the native mobile applications in the year 2018. This technology has many advantages, such as the ability to work offline, virtually no load time (because much of the information is stored in the cache of the phone), good reliability, and the ability to receive notifications. These progressive web apps can be designed faster than mobile applications, work for all users, and are generally easier to deploy and maintain, which is good for both the developer and the user.

This can maximize conversion rate by enabling the users to browse the Internet even when they are not connected to the Internet. However, despite being a relatively new technology, the progressive web application will continue to progress in 2018.

 

In conclusion, it's important for businesses to have both a strong online presence and competitive spirit, but also a flexible strategy based on web development trends in order to attract new customers, satisfy existing customers and encourage older customers to return.