Deploy Bots API #28

Merged
Quaternions merged 34 commits from staging into master 2026-02-28 02:33:43 +00:00
3 changed files with 16 additions and 6 deletions
Showing only changes of commit c8d0502616 - Show all commits

View File

@@ -2,9 +2,10 @@ package handlers
import (
"fmt"
"strconv"
"github.com/gin-gonic/gin"
"google.golang.org/grpc"
"strconv"
)
const (
@@ -14,6 +15,7 @@ const (
// Handler is a base handler that provides common functionality for all HTTP handlers.
type Handler struct {
dataClient *grpc.ClientConn
storageUrl string
}
// HandlerOption defines a functional option for configuring a Handler
@@ -26,6 +28,13 @@ func WithDataClient(dataClient *grpc.ClientConn) HandlerOption {
}
}
// WithStorageUrl sets the storage url
func WithStorageUrl(storageUrl string) HandlerOption {
return func(cfg *Handler) {
cfg.storageUrl = storageUrl
}
}
// NewHandler creates a new Handler with the provided options.
// It requires both a datastore and an authentication service to function properly.
func NewHandler(options ...HandlerOption) (*Handler, error) {

View File

@@ -22,18 +22,16 @@ import (
// TimesHandler handles HTTP requests related to times.
type TimesHandler struct {
*Handler
url string
}
// NewTimesHandler creates a new TimesHandler with the provided options.
func NewTimesHandler(storageUrl string, options ...HandlerOption) (*TimesHandler, error) {
func NewTimesHandler(options ...HandlerOption) (*TimesHandler, error) {
baseHandler, err := NewHandler(options...)
if err != nil {
return nil, err
}
return &TimesHandler{
Handler: baseHandler,
url: storageUrl,
}, nil
}
@@ -406,7 +404,7 @@ func (h *TimesHandler) GetDownloadUrl(ctx *gin.Context) {
// fetch download url from storage service
// Build the full URL.
fullURL, err := url.JoinPath(h.url, botData.FileID)
fullURL, err := url.JoinPath(h.storageUrl, botData.FileID)
if err != nil {
statusCode := http.StatusInternalServerError
errorMessage := "Error joining Url"

View File

@@ -85,7 +85,10 @@ func setupRoutes(cfg *RouterConfig) (*gin.Engine, error) {
}
// Times handler
timesHandler, err := handlers.NewTimesHandler(cfg.storageUrl, handlerOptions...)
timesHandler, err := handlers.NewTimesHandler([]handlers.HandlerOption{
handlers.WithDataClient(cfg.dataClient),
handlers.WithStorageUrl(cfg.storageUrl),
}...)
if err != nil {
return nil, err
}