Skip to main content

Golang Callback Server Example

Server.go (For PEM)

package main

import (
"crypto/tls"
"fmt"
"log"

"github.com/go-resty/resty/v2"
)

func main() {

certPath := "./certificate.pem"
keyPath := "./your_private.key"

// Load certificate and private key files
tlsCert, err := tls.LoadX509KeyPair(certPath, keyPath)
if err != nil {
log.Fatalf("failed to load key pair: %v", err)
}

tlsConfig := &tls.Config{
Certificates: []tls.Certificate{tlsCert},
InsecureSkipVerify: true, // use this only if you want to skip SSL verifications like -k option in curl
}

// Create a Resty Client
client := resty.New()
client.SetTLSClientConfig(tlsConfig)

resp, err := client.R().
SetBody(map[string]interface{}{
"vaspCode": "",
"accessKey": "",
"signedSecretKey": "",
"callbackUrl": "",
"vaspPublicKey": "",
}).
Post("https://platform.globaltravelrule.com/api/login")

if err != nil {
log.Fatalf("failed to send request: %s", err)
}

log.Println(string(resp.Body()))
}

Server.go (For P12)

package main

import (
"crypto/tls"
"fmt"
"io/ioutil"
"log"

"github.com/go-resty/resty/v2"
"software.sslmate.com/src/go-pkcs12"
)

func main() {
p12Path := "./certificate_1.p12"
p12Password := "password"

// Load .p12 file
p12Data, err := ioutil.ReadFile(p12Path)
if err != nil {
log.Fatalf("failed to read .p12 file: %v", err)
}

// Decode .p12 file
privateKey, certs, caCerts, err := pkcs12.DecodeChain(p12Data, p12Password)
if err != nil {
fmt.Errorf("failed to decode chain: %w", err)
}

certBytes := [][]byte{certs.Raw}
for _, ca := range caCerts {
certBytes = append(certBytes, ca.Raw)
}

tlsCert := tls.Certificate{
Certificate: certBytes,
PrivateKey: privateKey,
}

tlsConfig := &tls.Config{
Certificates: []tls.Certificate{tlsCert},
InsecureSkipVerify: true, // use this only if you want to skip SSL verifications like -k option in curl
}

// Create a Resty Client
client := resty.New()
client.SetTLSClientConfig(tlsConfig)

resp, err := client.R().
SetBody(map[string]interface{}{
"vaspCode": "",
"accessKey": "",
"signedSecretKey": "",
"callbackUrl": "",
"vaspPublicKey": "",
}).
Post("https://platform.globaltravelrule.com/api/login")

if err != nil {
log.Fatalf("failed to send request: %s", err)
}

log.Println(string(resp.Body()))
}
Copyright (C) 2024 Global Travel Rule. All Rights Reserved
General
Developer