Skip to content

Go SDK with reusable clients and helpers for Minisource services

Notifications You must be signed in to change notification settings

minisource/go-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Minisource Go SDK

Official Go SDK for all Minisource microservices. Provides both HTTP and gRPC clients for service-to-service communication.

Installation

go get github.com/minisource/go-sdk

Available Clients

Service HTTP Client gRPC Client Description
Auth Authentication and authorization
Notifier Notifications (SMS, Email, Push)
Storage File storage and management
Comment 🚧 Centralized commenting system
Log Centralized logging
Scheduler Job scheduling
Ticket Support ticket management
Feedback User feedback management

Legend: ✅ Available | 🚧 In Progress | ❌ Not Available

Quick Start

Authentication Client

import "github.com/minisource/go-sdk/auth"

// Create auth client
authClient := auth.NewClient(auth.ClientConfig{
    BaseURL:      "http://auth:9001",
    ClientID:     "my-service",
    ClientSecret: "secret",
    AutoRefresh:  true,
})

// Authenticate
authResp, err := authClient.Authenticate(ctx)

// Validate a token
claims, err := authClient.ValidateToken(ctx, token)

// Get token for service-to-service calls
token, err := authClient.GetToken(ctx)

Notifier Client (HTTP)

import "github.com/minisource/go-sdk/notifier"

// Create notifier client using HTTP
client := notifier.NewHTTPClient(notifier.HTTPConfig{
    BaseURL:    "http://notifier:9002",
    AuthClient: authClient,
})

// Send SMS
err := client.SendSMS(ctx, notifier.SMSRequest{
    TenantID:    "tenant-123",
    PhoneNumber: "+1234567890",
    Message:     "Hello!",
})

// Send Email
err := client.SendEmail(ctx, notifier.EmailRequest{
    TenantID: "tenant-123",
    To:       "user@example.com",
    Subject:  "Welcome",
    Body:     "Welcome to our platform!",
})

Notifier Client (gRPC)

import "github.com/minisource/go-sdk/notifier"

// Create gRPC client
client, err := notifier.NewClient(ctx, notifier.Config{
    Address:    "notifier:9003",
    AuthClient: authClient,
})
defer client.Close()

// Send notification
err := client.SendSMS(ctx, tenantID, &notifier.SMSRequest{
    PhoneNumber: "+1234567890",
    Message:     "Hello via gRPC!",
})

Comment Client

import "github.com/minisource/go-sdk/comment"

// Create comment client
client := comment.NewClient(comment.ClientConfig{
    BaseURL:      "http://comment:5010",
    ClientID:     cfg.Auth.ClientID,
    ClientSecret: cfg.Auth.ClientSecret,
})

// Create a comment
resp, err := client.Create(ctx, comment.CreateRequest{
    TenantID:   tenantID,
    EntityType: "ticket",
    EntityID:   ticketID,
    Content:    "This is a comment",
    AuthorID:   userID,
    AuthorName: userName,
})

// List comments
comments, err := client.List(ctx, tenantID, comment.ListFilter{
    EntityType: "ticket",
    EntityID:   ticketID,
    Page:       1,
    PerPage:    20,
})

// Add reaction
err := client.AddReaction(ctx, tenantID, commentID, userID, "like")

Storage Client

import "github.com/minisource/go-sdk/storage"

// Create storage client
client := storage.NewClient(storage.ClientConfig{
    BaseURL:    "http://storage:5004",
    AuthClient: authClient,
})

// Upload file
resp, err := client.Upload(ctx, storage.UploadRequest{
    TenantID: tenantID,
    File:     fileReader,
    Filename: "document.pdf",
    Folder:   "documents",
})

// Download file
data, err := client.Download(ctx, tenantID, fileID)

Log Client

import "github.com/minisource/go-sdk/log"

// Create log client
client := log.NewClient(log.ClientConfig{
    BaseURL:    "http://log:5002",
    AuthClient: authClient,
})

// Ingest logs
err := client.Ingest(ctx, log.LogEntry{
    Service:   "my-service",
    Level:     log.LevelInfo,
    Message:   "User logged in",
    TraceID:   traceID,
    RequestID: requestID,
})

// Query logs
results, err := client.Query(ctx, log.LogFilter{
    Service:   "my-service",
    Level:     log.LevelError,
    StartTime: time.Now().Add(-24 * time.Hour),
    EndTime:   time.Now(),
})

Scheduler Client

import "github.com/minisource/go-sdk/scheduler"

// Create scheduler client
client := scheduler.NewClient(scheduler.ClientConfig{
    BaseURL:    "http://scheduler:5003",
    AuthClient: authClient,
})

// Create a job
job, err := client.CreateJob(ctx, scheduler.CreateJobRequest{
    TenantID:    tenantID,
    Name:        "daily-report",
    Type:        scheduler.JobTypeCron,
    Schedule:    "0 9 * * *",
    WebhookURL:  "http://my-service/webhook/report",
    Payload:     map[string]interface{}{"report": "daily"},
})

// List jobs
jobs, err := client.ListJobs(ctx, tenantID, scheduler.JobFilter{
    Status: scheduler.JobStatusActive,
})

Ticket Client

import "github.com/minisource/go-sdk/ticket"

// Create ticket client
client := ticket.NewClient(ticket.ClientConfig{
    BaseURL:    "http://ticket:5011",
    AuthClient: authClient,
})

// Create ticket
ticket, err := client.Create(ctx, ticket.CreateTicketRequest{
    TenantID:    tenantID,
    Subject:     "Support request",
    Description: "Need help with...",
    Priority:    ticket.PriorityHigh,
})

// List tickets
tickets, err := client.List(ctx, tenantID, ticket.TicketFilter{
    Status: []ticket.TicketStatus{ticket.StatusOpen},
})

Feedback Client

import "github.com/minisource/go-sdk/feedback"

// Create feedback client
client := feedback.NewClient(feedback.ClientConfig{
    BaseURL:    "http://feedback:5012",
    AuthClient: authClient,
})

// Create feedback
fb, err := client.Create(ctx, feedback.CreateFeedbackRequest{
    TenantID:    tenantID,
    Title:       "Feature request",
    Description: "It would be great if...",
    CategoryID:  "features",
    AuthorID:    userID,
})

// Vote on feedback
err := client.Vote(ctx, tenantID, feedbackID, userID, feedback.VoteUpvote)

Configuration

All clients support common configuration options:

Option Description Default
BaseURL Service base URL Required
Timeout Request timeout 30s
AuthClient Auth client for authentication nil
Logger Logger instance Default logger
RetryConfig Retry configuration 3 retries

gRPC Support

Services with gRPC support use Protocol Buffers. To regenerate proto files:

# Install protoc plugins
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

# Generate from go-sdk root
make proto

Error Handling

All clients return errors that can be type-asserted for specific handling:

resp, err := client.Get(ctx, id)
if err != nil {
    if errors.Is(err, comment.ErrNotFound) {
        // Handle not found
    }
    return err
}

License

MIT

About

Go SDK with reusable clients and helpers for Minisource services

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published