MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / getCreateRouteHandler

Function getCreateRouteHandler

internal/server/web/admin/route.go:22–108  ·  view source on GitHub ↗
(m RouteManager, prod bool)

Source from the content-addressed store, hash-verified

20}
21
22func getCreateRouteHandler(m RouteManager, prod bool) gin.HandlerFunc {
23 return func(c *gin.Context) {
24 log := util.GetLogFromCtx(c)
25 telemetry.Incr("bricksllm.admin.get_create_route_handler.requests", nil, 1)
26
27 start := time.Now()
28 defer func() {
29 dur := time.Since(start)
30 telemetry.Timing("bricksllm.admin.get_create_route_handler.latency", dur, nil, 1)
31 }()
32
33 path := "/api/routes"
34 if c == nil || c.Request == nil {
35 c.JSON(http.StatusInternalServerError, &ErrorResponse{
36 Type: "/errors/empty-context",
37 Title: "context is empty error",
38 Status: http.StatusInternalServerError,
39 Detail: "gin context is empty",
40 Instance: path,
41 })
42 return
43 }
44
45 data, err := io.ReadAll(c.Request.Body)
46 if err != nil {
47 logError(log, "error when reading create a route request body", prod, err)
48 c.JSON(http.StatusInternalServerError, &ErrorResponse{
49 Type: "/errors/request-body-read",
50 Title: "request body reader error",
51 Status: http.StatusInternalServerError,
52 Detail: err.Error(),
53 Instance: path,
54 })
55 return
56 }
57
58 r := &route.Route{}
59 err = json.Unmarshal(data, r)
60 if err != nil {
61 logError(log, "error when unmarshalling create a route request body", prod, err)
62 c.JSON(http.StatusInternalServerError, &ErrorResponse{
63 Type: "/errors/json-unmarshal",
64 Title: "json unmarshaller error",
65 Status: http.StatusInternalServerError,
66 Detail: err.Error(),
67 Instance: path,
68 })
69 return
70 }
71
72 created, err := m.CreateRoute(r)
73 if err != nil {
74 errType := "internal"
75
76 defer func() {
77 telemetry.Incr("bricksllm.admin.get_create_route.create_route_error", []string{
78 "error_type:" + errType,
79 }, 1)

Callers 1

NewAdminServerFunction · 0.85

Calls 6

GetLogFromCtxFunction · 0.92
IncrFunction · 0.92
TimingFunction · 0.92
logErrorFunction · 0.70
ErrorMethod · 0.65
CreateRouteMethod · 0.65

Tested by

no test coverage detected