mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
Full module path rebrand from Temporal to Hanzo Tasks: - go.mod module: github.com/hanzoai/tasks - All internal Go imports updated (1906 files) - cmd/server renamed to cmd/tasksd - Binary name: tasksd (was temporal-server) - Docker images: hanzoai/tasks (was temporalio/server) - README rewritten with Hanzo Tasks branding - LLM.md created with integration notes - Makefile, goreleaser, CI workflows updated - go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos) Fork of Temporal.io (MIT license).
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package frontend
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"go.temporal.io/api/temporalproto/openapi"
|
|
"github.com/hanzoai/tasks/common/log"
|
|
"github.com/hanzoai/tasks/common/log/tag"
|
|
"github.com/hanzoai/tasks/common/rpc/interceptor"
|
|
"github.com/hanzoai/tasks/service/frontend/configs"
|
|
)
|
|
|
|
// Small wrapper that does some pre-processing before handing requests over to the OpenAPI SDK's HTTP handler.
|
|
type OpenAPIHTTPHandler struct {
|
|
logger log.Logger
|
|
rateLimitInterceptor *interceptor.RateLimitInterceptor
|
|
}
|
|
|
|
func NewOpenAPIHTTPHandler(
|
|
rateLimitInterceptor *interceptor.RateLimitInterceptor,
|
|
logger log.Logger,
|
|
) *OpenAPIHTTPHandler {
|
|
return &OpenAPIHTTPHandler{
|
|
logger: logger,
|
|
rateLimitInterceptor: rateLimitInterceptor,
|
|
}
|
|
}
|
|
|
|
func (h *OpenAPIHTTPHandler) RegisterRoutes(r *mux.Router) {
|
|
serve := func(version int, apiName string, contentType string, spec []byte) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := h.rateLimitInterceptor.Allow(apiName, r.Header); err != nil {
|
|
w.WriteHeader(http.StatusTooManyRequests)
|
|
return
|
|
}
|
|
|
|
rdr, err := gzip.NewReader(bytes.NewReader(spec))
|
|
if err != nil {
|
|
h.logger.Error("failed to initialize openapi spec reader", tag.Int("version", version), tag.Error(err))
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
if _, err := io.Copy(w, rdr); err != nil {
|
|
h.logger.Error("failed to send openapi spec", tag.Int("version", version), tag.Error(err))
|
|
}
|
|
if err := rdr.Close(); err != nil {
|
|
h.logger.Error("failed to verify openapi spec checksum", tag.Int("version", version), tag.Error(err))
|
|
}
|
|
}
|
|
}
|
|
|
|
r.PathPrefix("/swagger.json").Methods("GET").HandlerFunc(serve(
|
|
2,
|
|
configs.OpenAPIV2APIName,
|
|
"application/vnd.oai.openapi+json;version=2.0",
|
|
openapi.OpenAPIV2JSONSpec,
|
|
))
|
|
r.PathPrefix("/openapi.yaml").Methods("GET").HandlerFunc(serve(
|
|
3,
|
|
configs.OpenAPIV3APIName,
|
|
"application/vnd.oai.openapi;version=3.0",
|
|
openapi.OpenAPIV3YAMLSpec,
|
|
))
|
|
}
|