Backbench Docs
  • Introduction
  • Getting Started
    • BBLANG
    • Node
    • Python
    • Go
  • Backbench Features and UI workflow
  • API Reference
    • BBLANG
    • Node
    • Python
    • Go
  • 3rd Party Integrations
    • Login using Facebook
    • Login using Google
    • Login with Twitter
    • Login using LinkedIn
    • Connection with MongoDB
    • Connection with MySQL
    • Geo Location Integration
    • Integration with AWS S3
    • Integration with Google Cloud Storage
    • Integration with Razorpay
    • Integration with Stripe
    • Integration with Mailchimp
    • Integration with Segment
    • Sending Emails with SendGrid
    • Sending Emails with Mailgun
    • Sending SMS with Twilio
    • Sending Push Notification with Pushwoosh
  • Troubleshooting and support
    • CNAME Support
    • FAQS
    • Error Codes
  • Testing
Powered by GitBook
On this page
  • REST API
  • Helper Library
  1. API Reference

Go

REST API

See root documentation of API Reference.

Helper Library

You can use MemGet, MemSet, MemDel, Log anywhere in your code.

help.go
package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"strings"
	"os"
	"encoding/json"
)

type APIResponse struct {
	Status string `json:"status"`
	Reply string `json:"reply"`
}

func APIRoute(op string, m map[string]string) string{

	url := "https://memory.backbench.io/"

	bench := strings.Split(os.Getenv("benchName"), ":")
	fmt.Println("she dont know")
	str:="{\"cmd\": \""+op+"\",\"auth\": {\"userId\": \""+bench[0]+"\",\"benchId\": \""+bench[1]+"\",\"accessKey\": \""+os.Getenv("ACCESS_KEY")+"\"},\"args\": {\"message\": \""+m["message"]+"\",\"key\": \""+m["key"]+"\",\"value\": \""+m["value"]+"\"}}"
	// fmt.Println(str)
	payload := strings.NewReader(str)
	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("content-type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	var apir APIResponse
	err := json.Unmarshal(body, &apir)
	if err != nil {
		fmt.Println("error:", err)
	}
	// fmt.Printf("%+v", apir)
	// fmt.Println(apir)
	return apir.Reply
}

func MemGet(key string) string {
	m:= make(map[string]string)
	m["key"] = key
	r := APIRoute("bb:mem:get", m)
	if strings.Contains(r, "errorMessage") {
		return ""
	}

	return r
}

func MemSet(key string, value string) {
	m:= make(map[string]string)
	m["key"] = key
	m["value"] = value
	APIRoute("bb:mem:set", m)
}

func MemDel(key string) {
	m:= make(map[string]string)
	m["key"] = key
	APIRoute("bb:mem:del", m)
}

func Log(message string) {
	m:= make(map[string]string)
	m["message"] = message
	APIRoute("bb:log", m)
}
PreviousPythonNext3rd Party Integrations

Last updated 6 years ago