Developer Documentation
  • Introduction
  • Recipes
    • Using Recipes with Lingk APIs
  • Lingk REST APIs
    • Using Postman with Lingk APIs
    • Events & Webhooks
    • Code Samples
      • C#
      • ColdFusion
      • Go
      • Java
      • Node.js
      • PHP
      • Python
      • Salesforce Apex
  • API Explorer
  • API Plugin for Apache Nifi
    • Docker on Windows Installation Guide
    • Colleague Implementation Notes
    • Testing the API Plugin with Postman
Powered by GitBook
On this page

Was this helpful?

  1. Lingk REST APIs
  2. Code Samples

Go

import (
  "time"
  "fmt"
  "crypto/hmac"
  "crypto/sha1"
  "encoding/base64"
  "net/url"
  "os"
)

func main() {
  endpoint := os.Args[1]
  method := os.Args[2]

  theUrl, _ := url.Parse(endpoint)

  keyId := "[your key]"
  secret64 := "[your secret]"
  secret := []byte(secret64)

  now := time.Now().UTC()
  formatted := now.Format("Mon, 02 Jan 2006 15:04:05 MST")
  dateHeader := " -H \"Date: " + formatted + "\""

  mac := hmac.New(sha1.New, secret)
  mac.Write([]byte("date: " + formatted + "\n(request-target): " + strings.ToLower(method) + " " + theUrl.Path))
  macBytes := mac.Sum(nil)

  macEncoded := url.QueryEscape(base64.StdEncoding.EncodeToString(macBytes))
  signatureHeader := " -H 'Authorization: Signature keyId=\"" + keyId +
     "\",headers=\"date (request-target)\",algorithm=\"hmac-sha1\",signature=\"" + macEncoded + "\"'"

  if method == "POST" {
      fmt.Println("curl -n -X " + method + " -d @json.txt " + dateHeader + " " + signatureHeader +
      " " + endpoint + service)
  } else {
      fmt.Println("curl -n " + dateHeader + " " + signatureHeader + developerIdHeader +
      " " + endpoint + service)
  }
}
PreviousColdFusionNextJava

Last updated 5 years ago

Was this helpful?