Skip to content

Commit bbb060e

Browse files
committed
add checklFalg endpoint
1 parent 9563f26 commit bbb060e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

splitio/api/controllers/dtos.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package controllers
2+
3+
type SplitViewDTO struct {
4+
Name string `json:"name"`
5+
TrafficType string `json:"trafficType"`
6+
Killed bool `json:"killed"`
7+
Treatments []string `json:"treatments"`
8+
ChangeNumber int64 `json:"changeNumber"`
9+
Configs map[string]string `json:"configs"`
10+
DefaultTreatment string `json:"defaultTreatment"`
11+
Sets []string `json:"sets"`
12+
}

splitio/api/controllers/health.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type HealthCheckController struct {
1919
func (c *HealthCheckController) Register(router gin.IRouter) {
2020
router.GET("/health", c.isHealthy)
2121
router.GET("/ready", c.isReady)
22+
router.GET("/checkFlag", c.checkFlag)
2223
}
2324

2425
func (c *HealthCheckController) isHealthy(ctx *gin.Context) {
@@ -50,6 +51,39 @@ func (c *HealthCheckController) isReady(ctx *gin.Context) {
5051
ctx.Status(200)
5152
}
5253

54+
func (c *HealthCheckController) checkFlag(ctx *gin.Context) {
55+
56+
splitName := ctx.Request.URL.Query().Get("flag")
57+
conn, err := transfer.NewClientConn(c.logger, &c.connParams.Transfer)
58+
if conn != nil {
59+
defer conn.Shutdown()
60+
}
61+
if err != nil {
62+
ctx.AbortWithError(500, fmt.Errorf("error creating raw connection: %w", err))
63+
return
64+
}
65+
66+
serial, err := serializer.Setup(c.connParams.Serialization)
67+
if err != nil {
68+
ctx.AbortWithError(500, fmt.Errorf("error setting up serializer: %w", err))
69+
return
70+
}
71+
72+
rpcClient, err := client.New(c.logger, conn, serial, c.connParams.Consumer)
73+
if err != nil {
74+
ctx.AbortWithError(500, fmt.Errorf("error setting up client: %w", err))
75+
return
76+
}
77+
78+
result, err := rpcClient.Split(splitName)
79+
if err != nil {
80+
ctx.AbortWithError(500, fmt.Errorf("error issuing RPC: %w", err))
81+
return
82+
}
83+
84+
ctx.JSON(200, SplitViewDTO(*result))
85+
}
86+
5387
func NewHealthController(logger logging.LoggerInterface, connParams link.ConsumerOptions) *HealthCheckController {
5488
return &HealthCheckController{
5589
connParams: connParams,

splitio/commitsha.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package splitio
22

3-
const CommitSHA = "66886e2"
3+
const CommitSHA = "9563f26"

0 commit comments

Comments
 (0)