init
This commit is contained in:
32
internal/api/handlers/auth.go
Normal file
32
internal/api/handlers/auth.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// AuthHandler handles authentication-related requests
|
||||
type AuthHandler struct {
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewAuthHandler creates a new AuthHandler
|
||||
func NewAuthHandler(logger *zap.Logger) *AuthHandler {
|
||||
return &AuthHandler{
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// Login handles user login
|
||||
func (h *AuthHandler) Login(c *gin.Context) {
|
||||
// TODO: Implement login logic
|
||||
h.logger.Info("Login endpoint hit")
|
||||
c.JSON(200, gin.H{"message": "Login not implemented"})
|
||||
}
|
||||
|
||||
// Logout handles user logout
|
||||
func (h *AuthHandler) Logout(c *gin.Context) {
|
||||
// TODO: Implement logout logic
|
||||
h.logger.Info("Logout endpoint hit")
|
||||
c.JSON(200, gin.H{"message": "Logout not implemented"})
|
||||
}
|
||||
101
internal/api/handlers/dicom.go
Normal file
101
internal/api/handlers/dicom.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/proxy"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// DicomHandler handles DICOM Web requests
|
||||
type DicomHandler struct {
|
||||
client *proxy.Client
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
// NewDicomHandler creates a new DICOM handler
|
||||
func NewDicomHandler(client *proxy.Client, logger *zap.Logger) *DicomHandler {
|
||||
return &DicomHandler{
|
||||
client: client,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// ForwardRequest forwards the request to Google Healthcare API
|
||||
func (h *DicomHandler) ForwardRequest(c *gin.Context) {
|
||||
path := c.Param("path")
|
||||
requestType := getRequestType(c.Request.URL.Path)
|
||||
|
||||
h.logger.Debug("Forwarding request",
|
||||
zap.String("path", path),
|
||||
zap.String("method", c.Request.Method),
|
||||
zap.String("type", requestType),
|
||||
)
|
||||
|
||||
// Read request body if present
|
||||
var bodyBytes []byte
|
||||
if c.Request.Body != nil && c.Request.ContentLength > 0 {
|
||||
var err error
|
||||
bodyBytes, err = io.ReadAll(c.Request.Body)
|
||||
if err != nil {
|
||||
h.logger.Error("Failed to read request body", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Get request headers
|
||||
headers := make(map[string]string)
|
||||
for k, v := range c.Request.Header {
|
||||
if len(v) > 0 {
|
||||
headers[k] = v[0]
|
||||
}
|
||||
}
|
||||
|
||||
// Forward the request to Healthcare API
|
||||
response, err := h.client.ForwardRequest(
|
||||
c.Request.Context(),
|
||||
c.Request.Method,
|
||||
requestType,
|
||||
path,
|
||||
headers,
|
||||
bodyBytes,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
h.logger.Error("Request forwarding failed", zap.Error(err))
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": fmt.Sprintf("Request failed: %v", err)})
|
||||
return
|
||||
}
|
||||
|
||||
// Set response headers
|
||||
for k, v := range response.Headers {
|
||||
c.Header(k, v)
|
||||
}
|
||||
|
||||
// Set status and write response body
|
||||
c.Status(response.StatusCode)
|
||||
c.Writer.Write(response.Body)
|
||||
}
|
||||
|
||||
// getRequestType determines if the request is WADO, QIDO or STOW
|
||||
func getRequestType(path string) string {
|
||||
if len(path) < 9 {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
pathComponent := path[9:] // Remove "/dicomWeb/"
|
||||
|
||||
if len(pathComponent) >= 4 && pathComponent[:4] == "wado" {
|
||||
return "wado"
|
||||
} else if len(pathComponent) >= 4 && pathComponent[:4] == "qido" {
|
||||
return "qido"
|
||||
} else if len(pathComponent) >= 4 && pathComponent[:4] == "stow" {
|
||||
return "stow"
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
12
internal/api/handlers/healthcheck.go
Normal file
12
internal/api/handlers/healthcheck.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// HealthCheck is a simple health check handler
|
||||
func HealthCheck(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
}
|
||||
Reference in New Issue
Block a user