Go SDK

The Go SDK wraps the Surfinguard Rust engine via CGo and the FFI (Foreign Function Interface). It provides native Go bindings with the same 18 analyzers and 152 threat patterns.

Prerequisites

The Go SDK requires the libsurfinguard_ffi shared library to be built and available on your system.

Building the FFI Library

# From the surfinguard-platform repository
cd engine
cargo build --release
 
# The library will be at:
# macOS: engine/target/release/libsurfinguard_ffi.dylib
# Linux: engine/target/release/libsurfinguard_ffi.so

Set the library path:

# macOS
export DYLD_LIBRARY_PATH=/path/to/surfinguard-platform/engine/target/release:$DYLD_LIBRARY_PATH
 
# Linux
export LD_LIBRARY_PATH=/path/to/surfinguard-platform/engine/target/release:$LD_LIBRARY_PATH

Installation

go get github.com/surfinguard/go-sdk

Quick Start

package main
 
import (
    "fmt"
    surfinguard "github.com/surfinguard/go-sdk"
)
 
func main() {
    guard, err := surfinguard.NewGuard()
    if err != nil {
        panic(err)
    }
    defer guard.Close()
 
    result, err := guard.CheckUrl("https://g00gle-login.tk/verify")
    if err != nil {
        panic(err)
    }
 
    fmt.Printf("Level: %s\n", result.Level)   // "DANGER"
    fmt.Printf("Score: %d\n", result.Score)    // 9
    fmt.Printf("Reasons: %v\n", result.Reasons)
}

Available Methods

// URL analysis
result, err := guard.CheckUrl(url string)
 
// Command analysis
result, err := guard.CheckCommand(command string)
 
// Text / prompt injection detection
result, err := guard.CheckText(text string)
 
// File operations
result, err := guard.CheckFileRead(path string)
result, err := guard.CheckFileWrite(path string, content string)
 
// Universal check
result, err := guard.Check(actionType string, value string)
 
// Cleanup - must be called when done
guard.Close()

CheckResult

type CheckResult struct {
    Score      int               `json:"score"`
    Level      string            `json:"level"`
    Primitives map[string]int    `json:"primitives"`
    Reasons    []string          `json:"reasons"`
    Threats    []Threat          `json:"threats"`
}
 
type Threat struct {
    ID        string `json:"id"`
    Name      string `json:"name"`
    Score     int    `json:"score"`
    Primitive string `json:"primitive"`
}

Notes

  • The Go SDK uses CGo, which means it requires a C compiler and the FFI shared library at compile time and runtime.
  • Cross-compilation is limited by the need for the platform-specific FFI library.
  • For containerized deployments, include the .so/.dylib file in your container image.
  • The Go SDK currently supports the core check methods. Session tracking and policy enforcement are handled server-side via the API.