Last active
August 20, 2020 10:25
-
-
Save ashishmaurya/ac6d73a967310ddc3a9f459fa6fe6d90 to your computer and use it in GitHub Desktop.
Firebase Short link Creation - GO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/json" | |
"net/http" | |
"os" | |
) | |
//FirebaseShortLinkResponse ** | |
type FirebaseShortLinkResponse struct { | |
ShortLink string `json:"shortLink"` | |
} | |
//GenerateDynamicLink is used to Generate Dyanamic Firebase Redirection Link | |
func GenerateDynamicLink(token string) (string, error) { | |
domainName := "example.page.link" | |
APN := "example.android.com.app" | |
webAPI := "https://example.com/verify/" | |
ibi := "example.apple.io.app" | |
firebaseAPIKey := "FIREBASE_API_KEY" | |
linkURL := "https://app.example.com" | |
link := linkURL + "/" + token | |
webAPI = webAPI + token | |
dl := domainName + "/?link=" + link + "&apn=" + APN + "&afl=" + webAPI + "&ibi=" + ibi + "&ifl=" + webAPI + "&ipfl=" + webAPI + "&ofl=" + webAPI | |
var jsonStr = []byte(`{"longDynamicLink":"` + dl + `"}`) | |
req, err := http.NewRequest("POST", "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key="+firebaseAPIKey, bytes.NewBuffer(jsonStr)) | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
Logger().Error(err) | |
return "", err | |
} | |
objResponse := FirebaseShortLinkResponse{} | |
err2 := json.NewDecoder(resp.Body).Decode(&objResponse) | |
return objResponse.ShortLink, err2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment