Skip to content

lighthouse-web3/lighthouse-go-sdk

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Lighthouse-web3 Go SDK

Lighthouse Go SDK provides a robust way to interact with the Lighthouse platform for perpetual and decentralized file storage. This SDK enables seamless integration into Go applications, allowing you to upload, manage, and retrieve files on IPFS and Filecoin networks.

Installation

go get github.com/lighthouse-web3/lighthouse-go-sdk

Features Implemented

Client & Config

  • API key auth via WithAPIKey or LIGHTHOUSE_API_KEY env var

  • Configurable hosts, timeout, and user agent

Error Handling

  • Structured error type with status and message

Storage

  • File uploads (UploadFile, UploadReader) with optional progress callback

Files

  • List uploaded files

  • Get file info

  • Delete file (by Lighthouse file ID)

  • Pin file (by CID)

Deals Query Filecoin deal status for a CID

CLI (lhctl)

--upload <path> : Upload file

--list : List uploaded files

--info <cid> : Get file info

--delete <id> : Delete file by ID

--deals <cid> : Check deal status

Example Usage

Build CLI
go build -o lhctl ./cmd/lhctl
Upload file
LIGHTHOUSE_API_KEY=your-api-key ./lhctl --upload ./README.md
List files
LIGHTHOUSE_API_KEY=your-api-key ./lhctl --list
Get file info
LIGHTHOUSE_API_KEY=your-api-key ./lhctl --info <cid>
Delete file (by ID from --list)
LIGHTHOUSE_API_KEY=your-api-key ./lhctl --delete <id>

Quickstart (Go SDK)

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    "github.com/lighthouse-web3/lighthouse-go-sdk/lighthouse"
    "github.com/lighthouse-web3/lighthouse-go-sdk/lighthouse/schema"
)

func main() {
    // Create client
    client := lighthouse.NewClient(nil,
        lighthouse.WithAPIKey(os.Getenv("LIGHTHOUSE_API_KEY")),
    )

    ctx := context.Background()

    // Upload file with progress
    result, err := client.Storage().UploadFile(ctx, "README.md",
        schema.WithProgress(func(p schema.Progress) {
            fmt.Printf("\rUploading: %.1f%%", p.Percent())
        }),
    )
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("\nUploaded CID: %s\n", result.Hash)

    // Get file info
    info, err := client.Files().Info(ctx, result.Hash)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("File: %s (%d bytes)\n", info.FileName, info.FileSizeInBytes)

    // Check deals
    deals, err := client.Deals().Status(ctx, result.Hash)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Deals: %d\n", len(deals))
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%