# README
SDK 
This module will help you to quickly integrate with the API gateway.
Installation
Install SDK to your Go project.
go get github.com/TheUnitedCoders/devpost-auth0-api-gateway/pkg/sdk
Example of usage
- SDK Initialization. Create a context for working with the SDK and initialize it with the main parameters.
s, err := sdk.New(sdk.NewOptions{
ServerAddress: ":8001",
Auth0Domain: "<AUTH0_DOMAIN>",
Auth0Audience: "<AUTH0_AUDIENCE>",
M2MValidation: true,
GlobalHandlerSettings: sdk.HandlerSettings{
AuditEnabled: true,
RequiredAuthentication: true,
},
})
if err != nil {
slog.Error("Failed to init SDK", slog.String("error", err.Error()))
return
}
- Register method handlers with specific settings for each method:
err := s.RegisterHandler(sdk.Handler{
Method: "handler",
HandlerSettings: sdk.HandlerSettings{
RateLimiterDescription: &sdk.RateLimiterDescription{
By: sdk.RateLimitDescriptionBySubjectId, // Limit by user ID
Rate: 1, // Number of requests per minute
Burst: 1, // Burst value
Period: time.Minute, // Time period
},
RequiredPermissions: []string{"read:greeting"}, // Required access permissions
},
AllowedHTTPMethods: []sdk.HTTPMethod{sdk.HTTPMethodGet},
ProcessFunc: greetingProcess,
})
if err != nil {
slog.Error("Failed to register greeting handler", slog.String("error", err.Error()))
return
}
- Define the request processing function that will execute the processing logic and return a response:
func greetingProcess(ctx context.Context, req *sdk.ProcessRequest) (*sdk.ProcessResponse, error) {
name := req.Query.Get("name")
if name == "" {
name = "unknown :("
}
return &sdk.ProcessResponse{
Body: []byte(fmt.Sprintf(`{"msg": "hello from greeting-service to %s with auth0 ID %s"}`,
name, req.SubjectInformation.ID)),
StatusCode: http.StatusOK,
}, nil
}
- Running the Service
if err = s.Run(ctx); err != nil {
slog.Error("Failed to run SDK", slog.String("error", err.Error()))
}
The full example of usage can be found here. Also, full documentation available here.
# Packages
No description provided by the author
# Functions
New returns new SDK with provided options.
ParseHTTPMethod attempts to convert a string to a HTTPMethod.
ParseRateLimitDescriptionBy attempts to convert a string to a RateLimitDescriptionBy.
# Constants
HTTPMethodDelete is a HTTPMethod of type Delete.
HTTPMethodGet is a HTTPMethod of type Get.
HTTPMethodPatch is a HTTPMethod of type Patch.
HTTPMethodPost is a HTTPMethod of type Post.
HTTPMethodPut is a HTTPMethod of type Put.
HTTPMethodUnspecified is a HTTPMethod of type Unspecified.
RateLimitDescriptionByIp is a RateLimitDescriptionBy of type Ip.
RateLimitDescriptionBySubjectId is a RateLimitDescriptionBy of type Subject_id.
# Variables
No description provided by the author
No description provided by the author
# Structs
Handler ...
HandlerSettings ...
NewOptions ...
ProcessRequest ...
ProcessResponse ...
RateLimiterDescription ...
SDK that helps integrate with api-gateway.
SubjectInformation ...