Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Go CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-go-build
cancel-in-progress: true

steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.21'

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
with:
workspaces: rust

- name: Build Rust FFI library
run: cargo build --release
working-directory: rust

- name: Build Go bindings
run: go build ./...
working-directory: go
env:
CGO_ENABLED: 1

- name: Run unit tests
run: go test -v ./... 2>&1 | tee test-output.txt
working-directory: go
env:
CGO_ENABLED: 1

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: go-test-results
path: go/test-output.txt
retention-days: 5
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ dart/ant_ffi/*.dll
dart/ant_ffi/*.so
dart/ant_ffi/*.dylib
dart/c_header/

# Go bindings
go/antffi_test/*.dll
go/antffi_test/*.so
go/antffi_test/*.dylib
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Multi-platform bindings for the Autonomi network.
| C#/.NET | C# | Available |
| Lua | LuaJIT | Available |
| Dart/Flutter | Dart | Available |
| Go | Go | Available |
| C/C++ | C | Available |

## Android
Expand Down Expand Up @@ -426,6 +427,68 @@ The same bindings work for Flutter apps. Add the native library to your platform
- Android: `android/app/src/main/jniLibs/<arch>/libant_ffi.so`
- iOS: Link as a static library or framework

## Go

Go bindings using CGO to call the native Rust FFI library.

### Prerequisites

- Go 1.21 or later
- CGO enabled (`CGO_ENABLED=1`)
- C compiler (GCC/Clang on Linux/macOS, MinGW on Windows)
- The native `ant_ffi` shared library built from source

### Quick Start

```go
package main

import (
"context"
"fmt"
"github.com/maidsafe/ant-ffi/go/antffi"
)

func main() {
// Encrypt and decrypt data locally
data := []byte("Hello, Autonomi!")
encrypted, _ := antffi.Encrypt(data)
decrypted, _ := antffi.Decrypt(encrypted)
fmt.Println(string(decrypted)) // "Hello, Autonomi!"

// Initialize client (when network is available)
ctx := context.Background()
client, _ := antffi.NewClientLocal(ctx)
defer client.Free()

// Create a wallet
network, _ := antffi.NewNetwork(true) // local network
defer network.Free()
wallet, _ := antffi.NewWalletFromPrivateKey(network, "your-private-key")
defer wallet.Free()

// Upload data
payment := &antffi.PaymentOption{Wallet: wallet}
result, _ := client.DataPutPublic(ctx, []byte("Hello Autonomi!"), payment)
fmt.Printf("Uploaded to: %s\n", result.Address)

// Download data
downloaded, _ := client.DataGetPublic(ctx, result.Address)
fmt.Printf("Downloaded: %s\n", string(downloaded))
}
```

### Usage Examples

For comprehensive usage examples, see the test files in [`go/antffi_test/`](go/antffi_test/):

| Test File | Features Covered |
|-----------|------------------|
| `client_test.go` | Client init, data upload/download, pointers, wallets |
| `keys_test.go` | Secret keys, public keys, main secret keys, key derivation |
| `data_test.go` | Chunks, addresses, data map operations |
| `selfencryption_test.go` | Self-encryption, decryption, byte round-trips |

## C/C++

A C-compatible API is available for integration with C, C++, and any language that supports C FFI.
Expand Down
Loading
Loading