|
|
@ -2,15 +2,16 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"database/sql"
|
|
|
|
"database/sql"
|
|
|
|
"strconv"
|
|
|
|
"encoding/base64"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"encoding/json"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"encoding/base64"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
|
|
"mast/db"
|
|
|
|
"mast/db"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
"github.com/gorilla/websocket"
|
|
|
|
sqlite3 "github.com/mattn/go-sqlite3"
|
|
|
|
sqlite3 "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -97,19 +98,19 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
|
|
|
change.Seq = int64(m["Seq"].(float64))
|
|
|
|
change.Seq = int64(m["Seq"].(float64))
|
|
|
|
|
|
|
|
|
|
|
|
// Handle []byte fields
|
|
|
|
// Handle []byte fields
|
|
|
|
change.PK, err = base64.URLEncoding.DecodeString(m["PK"].(string))
|
|
|
|
change.PK, err = decodeBase64ToByteArray(m["PK"].(string))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return change, err
|
|
|
|
return change, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//fmt.Println(m["PK"])
|
|
|
|
//fmt.Println(m["PK"])
|
|
|
|
//fmt.Println(m["PK"].(string))
|
|
|
|
//fmt.Println(m["PK"].(string))
|
|
|
|
//fmt.Println(base64.URLEncoding.DecodeString(m["PK"].(string)))
|
|
|
|
//fmt.Println(base64.URLEncoding.DecodeString(m["PK"].(string)))
|
|
|
|
change.Value, err = base64.URLEncoding.DecodeString(m["Value"].(string))
|
|
|
|
change.Value, err = decodeBase64ToByteArray(m["Value"].(string))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return change, err
|
|
|
|
return change, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//change.SiteID, err = decodeBase64ToIntArray(m["SiteID"].(string))
|
|
|
|
change.SiteID, err = decodeBase64ToByteArray(m["SiteID"].(string))
|
|
|
|
change.SiteID, err = base64.URLEncoding.DecodeString(m["SiteID"].(string))
|
|
|
|
fmt.Println(change.SiteID)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return change, err
|
|
|
|
return change, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -118,7 +119,7 @@ func mapToCRSQLChange(m map[string]interface{}) (CRSQLChange, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
|
|
|
func decodeBase64ToByteArray(encodedString string) ([]uint8, error) {
|
|
|
|
// Decode the base64 string
|
|
|
|
// Decode the base64 string
|
|
|
|
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
|
|
|
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -132,13 +133,13 @@ func decodeBase64ToIntArray(encodedString string) ([]int, error) {
|
|
|
|
stringSlice := strings.Split(decodedString, ",")
|
|
|
|
stringSlice := strings.Split(decodedString, ",")
|
|
|
|
|
|
|
|
|
|
|
|
// Convert each string to an integer
|
|
|
|
// Convert each string to an integer
|
|
|
|
intSlice := make([]int, len(stringSlice))
|
|
|
|
intSlice := make([]uint8, len(stringSlice))
|
|
|
|
for i, s := range stringSlice {
|
|
|
|
for i, s := range stringSlice {
|
|
|
|
num, err := strconv.Atoi(s)
|
|
|
|
num, err := strconv.Atoi(s)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error converting string to int: %w", err)
|
|
|
|
return nil, fmt.Errorf("error converting string to int: %w", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
intSlice[i] = num
|
|
|
|
intSlice[i] = byte(num)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return intSlice, nil
|
|
|
|
return intSlice, nil
|
|
|
@ -162,7 +163,7 @@ func applyChanges(changes []interface{}) {
|
|
|
|
log.Println("Error inserting change:", err)
|
|
|
|
log.Println("Error inserting change:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Println("We inserted data successfully??")
|
|
|
|
log.Println("We inserted data successfully??")
|
|
|
|
printChange(change)
|
|
|
|
fmt.Println(c)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
fmt.Println("Not OK to convert change")
|
|
|
|
fmt.Println("Not OK to convert change")
|
|
|
|
fmt.Println("Change look like:")
|
|
|
|
fmt.Println("Change look like:")
|
|
|
|