mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-18 11:02:54 +00:00
- Add README.md with installation instructions, architecture overview, and API examples for all SDK modules - Add AuthProvider class with API key and JWT token support (GenerateJWTToken, ValidateJWTToken, GetHeaders, ClearTokenCache methods) - Add HTTPClient base class with retry logic, error handling, and timeout management - Add GraphQLAPI, PaymentsAPI, RatingPlansAPI
Telecom Platform Go SDK
Go SDK for the Telecom Platform with modular architecture for HTTP and gRPC support.
Features
- Modular Architecture: Separate modules for authentication, HTTP client, and API services
- Dual Protocol Support: Both HTTP REST and gRPC APIs
- Type Safety: Strong typing with Go structs
- Context Support: Full context.Context support
- Error Handling: Comprehensive error handling
- Retry Logic: Built-in retry mechanism
- Async Operations: Non-blocking operations
Architecture
The SDK is organized into modular components:
auth.go- Authentication provider handling API keys and JWT tokensclient.go- HTTP client with retry logic and authenticationsubscribers_api.go- Subscriber management APIusage_api.go- Usage tracking APIpayments_api.go- Payment processing APIrating_plans_api.go- Rating plan management APIsystem_api.go- System monitoring APIgraphql_api.go- GraphQL query executiontelecom.go- Main client integrating all modules
Installation
go get github.com/nutcas3/telecom-sdk-go
Quick Start
HTTP Client
package main
import (
"context"
"fmt"
"time"
"github.com/nutcas3/telecom-sdk-go"
)
func main() {
config := telecom.DefaultConfig()
config.APIKey = "your-api-key"
client, err := telecom.NewClient(config)
if err != nil {
panic(err)
}
defer client.Close()
ctx := context.Background()
// Get subscriber
subscriber, err := client.Subscribers.Get(ctx, 1)
if err != nil {
panic(err)
}
fmt.Printf("Subscriber: %s %s\n", subscriber.FirstName, subscriber.LastName)
// List subscribers
list, err := client.Subscribers.List(ctx, 1, 50)
if err != nil {
panic(err)
}
fmt.Printf("Total subscribers: %d\n", list.Total)
}
gRPC Client
package main
import (
"context"
"fmt"
"github.com/nutcas3/telecom-sdk-go"
)
func main() {
config := telecom.DefaultConfig()
config.APIKey = "your-api-key"
config.EnableGRPC = true
config.EnableHTTP = false // Only gRPC
client, err := telecom.NewClient(config)
if err != nil {
panic(err)
}
defer client.Close()
ctx := context.Background()
// Get subscriber via gRPC
req := &telecom.GetSubscriberRequest{Id: 1}
subscriber, err := client.GetSubscriberGRPC(ctx, req)
if err != nil {
panic(err)
}
fmt.Printf("Subscriber: %s %s\n", subscriber.FirstName, subscriber.LastName)
}
API Reference
Configuration
config := &telecom.Config{
APIURL: "http://localhost:8000",
GRPCURL: "localhost:50051",
APIKey: "your-api-key",
Timeout: 30 * time.Second,
Retries: 3,
EnableGRPC: true,
EnableHTTP: true,
}
Subscriber Management
// Get subscriber
subscriber, err := client.Subscribers.Get(ctx, 1)
// List subscribers
list, err := client.Subscribers.List(ctx, 1, 50, "")
// Create subscriber
req := &telecom.CreateSubscriberRequest{
IMSI: "208930000000001",
MSISDN: "+1234567890",
FirstName: "John",
LastName: "Doe",
Email: "[email protected]",
PlanID: 1,
}
subscriber, err := client.Subscribers.Create(ctx, req)
// Update subscriber
updateReq := &telecom.UpdateSubscriberRequest{
FirstName: stringPtr("Jane"),
}
subscriber, err := client.Subscribers.Update(ctx, 1, updateReq)
// Delete subscriber
err := client.Subscribers.Delete(ctx, 1)
// Suspend subscriber
subscriber, err := client.Subscribers.Suspend(ctx, 1)
// Activate subscriber
subscriber, err := client.Subscribers.Activate(ctx, 1)
Usage Management
// Get usage stats
stats, err := client.Usage.GetStats(ctx, 1, time.Now().AddDate(0, -1, 0), time.Now())
fmt.Printf("Data usage: %d bytes\n", stats.DataUp + stats.DataDown)
// List usage events
events, err := client.Usage.ListEvents(ctx, 1, "", 1, 50)
// Get real-time usage
realtime, err := client.Usage.GetRealTime(ctx, 1)
Payment Management
// Create payment transaction
req := &telecom.CreatePaymentRequest{
SubscriberID: "1",
Amount: 25.00,
Currency: "USD",
Gateway: "stripe",
}
transaction, err := client.Payments.CreateTransaction(ctx, req)
// Get transaction
transaction, err := client.Payments.GetTransaction(ctx, "txn-123")
// List transactions
transactions, err := client.Payments.ListTransactions(ctx, 1, "", 1, 50)
Rating Plans
// List rating plans
plans, err := client.RatingPlans.List(ctx)
// Get specific plan
plan, err := client.RatingPlans.Get(ctx, "plan-123")
System Management
// Get system stats
stats, err := client.System.GetStats(ctx)
fmt.Printf("Active sessions: %d\n", stats.ActiveSessions)
// Get health status
health, err := client.System.GetHealth(ctx)
Error Handling
subscriber, err := client.Subscribers.Get(ctx, 1)
if err != nil {
switch {
case strings.Contains(err.Error(), "HTTP error: 401"):
fmt.Println("Authentication failed")
case strings.Contains(err.Error(), "HTTP error: 404"):
fmt.Println("Subscriber not found")
case strings.Contains(err.Error(), "HTTP error: 500"):
fmt.Println("Server error")
default:
fmt.Printf("Error: %v\n", err)
}
}
gRPC Service Interfaces
The SDK provides interfaces for all gRPC services:
SubscriberServiceClient- Subscriber managementPaymentServiceClient- Payment processingUsageServiceClient- Usage trackingSystemServiceClient- System monitoring
Development
Running Tests
go test ./...
Code Coverage
go test -cover ./...
Building
go build ./...
License
This SDK is licensed under the MIT License.