# Go SDK The Monad Go SDK provides a robust client interface for interacting with the Monad API. ## Installation To use the Monad Go SDK in your project, install it using: ```bash go get github.com/monad-inc/sdk/go ``` ## Configuration ### Configuration Options The `Configuration` struct accepts the following parameters: - `HTTPClient`: Custom HTTP client (optional) - `Scheme`: Protocol scheme ("http" or "https") - `DefaultHeader`: Default headers for all requests - `Servers`: List of server configurations - `Debug`: Setting to true logs all HTTP request and response details. ### Example Configuration ```go config := &monad.Configuration{ HTTPClient: &http.Client{ Timeout: 10 * time.Second, Transport: &http.Transport{}, }, Scheme: "https", DefaultHeader: map[string]string{ "Authorization": "ApiKey YOUR_API_KEY", }, Servers: []monad.ServerConfiguration{ { URL: "app.monad.com/api", }, }, Debug: true, } c := monad.NewAPIClient(config) ``` The API Key can be obtained from the Monad UI in the organizations page. ## API Services Monad provides access to several APIs to perform fundamental operations through the client created above, such as creating inputs through the Organization Inputs API, creating Outputs from the Organization Outputs API, transforms with the Organization Transforms API, creating Pipelines with the Pipelines API, and more. ### Type-Safe Component System The Monad Go SDK implements a comprehensive type system that ensures type safety across all components (inputs, outputs, and transforms). Each component type has its own dedicated configuration structs that enforce proper configuration at compile-time. ### Complete Pipeline Example Below is a complete example that demonstrates creating a pipeline with a Semgrep input, a Splunk output, and a Timestamp transform using the Go SDK. The example shows how to create all components and connect them in a single pipeline. ```go package main import ( "context" "net/http" "time" "github.com/google/uuid" "github.com/monad-inc/sdk/go" ) // Helper function to convert any value to a pointer func toPtr[T any](in T) *T { return &in } func main() { // Initialize the Monad client configuration config := &monad.Configuration{ HTTPClient: &http.Client{ Timeout: 10 * time.Second, Transport: &http.Transport{}, }, Scheme: "https", DefaultHeader: map[string]string{ "Authorization": "ApiKey YOUR_API_KEY", }, Servers: []monad.ServerConfiguration{ { URL: "app.monad.com/api", }, }, Debug: true, } // Create the API client c := monad.NewAPIClient(config) ctx := context.Background() orgID := "YOUR_ORG_ID" // Step 1: Creates a Semgrep input inputName := "semgrep-input-" + uuid.New().String() in, _, err := c.OrganizationInputsAPI.V2OrganizationIdInputsPost(ctx, orgID).RoutesV2CreateInputRequest( monad.RoutesV2CreateInputRequest{ Name: toPtr(inputName), Type: toPtr("semgrep-projects"), Config: &monad.RoutesV2InputConfig{ Settings: &monad.RoutesV2InputConfigSettings{ SemgrepProjectDetailsSettingsConfig: &monad.SemgrepProjectDetailsSettingsConfig{ Cron: toPtr("* * * * *"), }, }, Secrets: &monad.RoutesV2InputConfigSecrets{ SemgrepProjectsSecretsConfig: &monad.SemgrepProjectsSecretsConfig{ ApiKey: toPtr("YOUR_SEMGREP_API_KEY"), }, }, }, }, ).Execute() if err != nil { panic(err) } // Step 2: Creates a Splunk output outputName := "splunk-output-" + uuid.New().String() out, _, err := c.OrganizationOutputsAPI.V2OrganizationIdOutputsPost(ctx, orgID).RoutesV2CreateOutputRequest( monad.RoutesV2CreateOutputRequest{ Name: toPtr(outputName), OutputType: toPtr("splunk"), Config: &monad.RoutesV2OutputConfig{ Settings: &monad.RoutesV2OutputConfigSettings{ SplunkSettingsConfig: &monad.SplunkSettingsConfig{ Url: toPtr("YOUR_SPLUNK_URL"), Port: toPtr("YOUR_SPLUNK_PORT"), AllowInsecure: toPtr(false), }, }, Secrets: &monad.RoutesV2OutputConfigSecrets{ SplunkSecretsConfig: &monad.SplunkSecretsConfig{ Token: toPtr("YOUR_SPLUNK_TOKEN"), }, }, }, }, ).Execute() if err != nil { panic(err) } // Step 3: Creates a timestamp transform transformName := "timestamp-transform-" + uuid.New().String() t, _, err := c.OrganizationTransformsAPI.V1OrganizationIdTransformsPost(ctx, orgID).RoutesCreateTransformRequest( monad.RoutesCreateTransformRequest{ Name: transformName, Config: &monad.ModelsTransformConfig{ Operations: []monad.ModelsTransformOperation{ { Operation: toPtr("timestamp"), Arguments: map[string]interface{}{ "key": "timestamp", "format": "2006-01-02T15:04:05Z07:00", }, }, }, }, }, ).Execute() if err != nil { panic(err) } const ( inputSlug = "input-semgrep" transformSlug = "transform-timestamp" outputSlug = "output-splunk" ) // Step 4: Creates the pipeline connecting all components p, _, err := c.PipelinesAPI.V2OrganizationIdPipelinesPost(ctx, orgID).RoutesV2CreatePipelineRequest( monad.RoutesV2CreatePipelineRequest{ Name: "semgrep-to-splunk-pipeline-" + uuid.New().String(), Description: toPtr("Pipeline connecting Semgrep input to Splunk output with timestamp transform"), Enabled: true, // Defines the pipeline nodes (components) Nodes: []monad.RoutesV2PipelineRequestNode{ { ComponentId: *in.Id, ComponentType: "input", Enabled: true, Slug: toPtr(inputSlug), }, { ComponentId: *t.Id, ComponentType: "transform", Enabled: true, Slug: toPtr(transformSlug), }, { ComponentId: *out.Id, ComponentType: "output", Enabled: true, Slug: toPtr(outputSlug), }, }, // Defines the connections between nodes Edges: []monad.RoutesV2PipelineRequestEdge{ { FromNodeInstanceId: inputSlug, ToNodeInstanceId: transformSlug, Name: toPtr("edge-" + uuid.New().String()), Description: toPtr("Edge connecting Semgrep input to timestamp transform"), Conditions: &monad.ModelsPipelineEdgeConditions{ Operator: toPtr("always"), }, }, { FromNodeInstanceId: transformSlug, ToNodeInstanceId: outputSlug, Name: toPtr("edge-" + uuid.New().String()), Description: toPtr("Edge connecting timestamp transform to Splunk output"), Conditions: &monad.ModelsPipelineEdgeConditions{ Operator: toPtr("always"), }, }, }, }, ).Execute() if err != nil { panic(err) } } ``` This example demonstrates: - Creating and configuring all components in a single flow - Using descriptive slugs for pipeline nodes - Proper error handling - Clear component connections using edges - Type-safe configuration for all components ## Support For additional support contact support@monad.com