Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AGEHandler ¶
type AGEHandler struct {
// contains filtered or unexported fields
}
AGEHandler exposes AGE (Apache Graph Extension) graphs via REST WIP: only basic queries / functionalities have been tested
Example ¶
package main
import (
"cmp"
"context"
"fmt"
"log"
"net/http"
"net/http/httptest"
"os"
"strings"
rest "github.com/edgeflare/pigo/pkg/x/age"
"github.com/jackc/pgx/v5/pgxpool"
)
func main() {
// Initialize a connection pool
ctx := context.Background()
graphName := "test_cypher"
pool, err := pgxpool.New(ctx, cmp.Or(os.Getenv("DATABASE_URL"), "postgres://postgres:secret@localhost:5432/testdb"))
if err != nil {
log.Fatalf("failed to create connection pool: %v", err)
}
defer pool.Close()
// Create an AGE handler with a default graph
handler, err := rest.NewAGEHandler(ctx, pool, graphName)
if err != nil {
log.Fatalf("failed to create AGE handler: %v", err)
}
defer handler.Close()
// Setup a test HTTP server
server := httptest.NewServer(handler)
defer server.Close()
// // or mount on specific /path
// mux := http.NewServeMux()
// mux.Handle("POST /graph", handler)
// if err = http.ListenAndServe(":8080", mux); err != nil {
// log.Fatalf("Server error: %v", err)
// }
// Example 1: Create a vertex
createReq := `{
"cypher": "CREATE (n:Person {name: 'Alice', age: 30}) RETURN n",
"columnCount": 1
}`
resp, err := http.Post(server.URL, "application/json", strings.NewReader(createReq))
if err != nil {
log.Fatalf("failed to send request: %v", err)
}
defer resp.Body.Close()
fmt.Printf("Create vertex status: %d\n", resp.StatusCode)
// Example 2: Query vertices
queryReq := `{
"cypher": "MATCH (n:Person) RETURN n",
"columnCount": 1
}`
resp, err = http.Post(server.URL, "application/json", strings.NewReader(queryReq))
if err != nil {
log.Fatalf("failed to send request: %v", err)
}
defer resp.Body.Close()
fmt.Printf("Query vertices status: %d\n", resp.StatusCode)
}
Output: Create vertex status: 200 Query vertices status: 200
func NewAGEHandler ¶
NewAGEHandler creates and configures a new API server
func (*AGEHandler) Close ¶
func (s *AGEHandler) Close()
Close performs cleanup when shutting down the server
func (*AGEHandler) ServeHTTP ¶
func (s *AGEHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP processes Cypher queries
type AGERequest ¶
type AGERequest struct {
Cypher string `json:"cypher"`
ColumnCount int `json:"columnCount,omitempty"` // for read requests. not required for write requests
}
AGERequest is the expected format for incoming API requests
type AGEResponse ¶
type AGEResponse struct {
Success bool `json:"success"`
Data any `json:"data,omitempty"`
Error string `json:"error,omitempty"`
}
AGEResponse is the format for API responses
Click to show internal directories.
Click to hide internal directories.