Files
tasks/service/frontend/openapi_http_handler.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
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).
2026-03-19 10:36:40 -07:00

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,
))
}